mirror of
https://github.com/BreizhHardware/memoizee.git
synced 2026-01-18 16:37:21 +01:00
profileName option
This commit is contained in:
@@ -90,6 +90,7 @@ module.exports = function (original, length, options) {
|
||||
conf = {
|
||||
original: original,
|
||||
memoized: memoized,
|
||||
profileName: options.profileName,
|
||||
get: function (args) {
|
||||
if (resolve) args = resolve(args);
|
||||
if (get) return get(args);
|
||||
|
||||
22
profile.js
22
profile.js
@@ -5,6 +5,7 @@
|
||||
var partial = require('es5-ext/function/#/partial')
|
||||
, forEach = require('es5-ext/object/for-each')
|
||||
, pad = require('es5-ext/string/#/pad')
|
||||
, compact = require('es5-ext/array/#/compact')
|
||||
, d = require('d')
|
||||
, memoize = require('./plain')
|
||||
|
||||
@@ -12,17 +13,18 @@ var partial = require('es5-ext/function/#/partial')
|
||||
, stats = exports.statistics = {};
|
||||
|
||||
Object.defineProperty(memoize, '__profiler__', d(function (conf) {
|
||||
var id, stack, data;
|
||||
var id, source, data, stack;
|
||||
stack = (new Error()).stack;
|
||||
if (!stack || !stack.split('\n').slice(3).some(function (line) {
|
||||
if ((line.indexOf('/memoizee/') === -1) &&
|
||||
(line.indexOf(' (native)') === -1)) {
|
||||
id = line.replace(/\n/g, "\\n").trim();
|
||||
return true;
|
||||
}
|
||||
})) {
|
||||
id = 'unknown';
|
||||
}
|
||||
if (!stack || !stack.split('\n').slice(3).some(function (line) {
|
||||
if ((line.indexOf('/memoizee/') === -1) &&
|
||||
(line.indexOf(' (native)') === -1)) {
|
||||
source = line.replace(/\n/g, "\\n").trim();
|
||||
return true;
|
||||
}
|
||||
})) {
|
||||
source = 'unknown';
|
||||
}
|
||||
id = compact.call([conf.profileName, source]).join(', ');
|
||||
|
||||
if (!stats[id]) stats[id] = { initial: 0, cached: 0 };
|
||||
data = stats[id];
|
||||
|
||||
@@ -4,8 +4,9 @@ var memoize = require('../plain');
|
||||
|
||||
module.exports = function (t, a) {
|
||||
memoize(function () {})();
|
||||
memoize(function () {}, { profileName: 'test' })();
|
||||
a(typeof t.statistics, 'object', "Access to statistics");
|
||||
a(Object.keys(t.statistics).length > 0, true, "Statistics collected");
|
||||
a(Object.keys(t.statistics).length, 2, "Statistics collected including named function");
|
||||
a(typeof t.log, 'function', "Access to log function");
|
||||
a(typeof t.log(), 'string', "Log outputs string");
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user