summaryrefslogtreecommitdiff
path: root/perf
diff options
context:
space:
mode:
Diffstat (limited to 'perf')
-rwxr-xr-xperf/benchmark.js248
-rw-r--r--perf/memory.js62
-rw-r--r--perf/suites.js472
3 files changed, 391 insertions, 391 deletions
diff --git a/perf/benchmark.js b/perf/benchmark.js
index e943f10..c3fb4d2 100755
--- a/perf/benchmark.js
+++ b/perf/benchmark.js
@@ -48,168 +48,168 @@ console.log("--------------------------------------");
async.eachSeries(versionNames, cloneVersion, function (err) {
- if (err) { throw err; }
- versions = versionNames.map(requireVersion);
-
- var suites = suiteConfigs
- .map(setDefaultOptions)
- .reduce(handleMultipleArgs, [])
- .map(setName)
- .filter(matchesGrep)
- .filter(doesNotMatch)
- .map(createSuite);
-
- async.eachSeries(suites, runSuite, function () {
- var totalTime0 = +totalTime[version0].toPrecision(3);
- var totalTime1 = +totalTime[version1].toPrecision(3);
-
- var wins0 = wins[version0];
- var wins1 = wins[version1];
-
- if ( Math.abs((totalTime0 / totalTime1) - 1) < 0.01) {
- // if < 1% difference, we're likely within the margins of error
- console.log("Both versions are about equal " +
- "(" + totalTime0 + "ms total vs. " + totalTime1 + "ms total)");
- } else if (totalTime0 < totalTime1) {
- console.log(version0 + " faster overall " +
- "(" + totalTime0 + "ms total vs. " + totalTime1 + "ms total)");
- } else if (totalTime1 < totalTime0) {
- console.log(version1 + " faster overall " +
- "(" + totalTime1 + "ms total vs. " + totalTime0 + "ms total)");
- }
-
- if (wins0 > wins1) {
- console.log(version0 + " won more benchmarks " +
- "(" + wins0 + " vs. " + wins1 + ")");
- } else if (wins1 > wins0) {
- console.log(version1 + " won more benchmarks " +
- "(" + wins1 + " vs. " + wins0 + ")");
- } else {
- console.log("Both versions won the same number of benchmarks " +
- "(" + wins0 + " vs. " + wins1 + ")");
- }
- });
+ if (err) { throw err; }
+ versions = versionNames.map(requireVersion);
+
+ var suites = suiteConfigs
+ .map(setDefaultOptions)
+ .reduce(handleMultipleArgs, [])
+ .map(setName)
+ .filter(matchesGrep)
+ .filter(doesNotMatch)
+ .map(createSuite);
+
+ async.eachSeries(suites, runSuite, function () {
+ var totalTime0 = +totalTime[version0].toPrecision(3);
+ var totalTime1 = +totalTime[version1].toPrecision(3);
+
+ var wins0 = wins[version0];
+ var wins1 = wins[version1];
+
+ if ( Math.abs((totalTime0 / totalTime1) - 1) < 0.01) {
+ // if < 1% difference, we're likely within the margins of error
+ console.log("Both versions are about equal " +
+ "(" + totalTime0 + "ms total vs. " + totalTime1 + "ms total)");
+ } else if (totalTime0 < totalTime1) {
+ console.log(version0 + " faster overall " +
+ "(" + totalTime0 + "ms total vs. " + totalTime1 + "ms total)");
+ } else if (totalTime1 < totalTime0) {
+ console.log(version1 + " faster overall " +
+ "(" + totalTime1 + "ms total vs. " + totalTime0 + "ms total)");
+ }
+
+ if (wins0 > wins1) {
+ console.log(version0 + " won more benchmarks " +
+ "(" + wins0 + " vs. " + wins1 + ")");
+ } else if (wins1 > wins0) {
+ console.log(version1 + " won more benchmarks " +
+ "(" + wins1 + " vs. " + wins0 + ")");
+ } else {
+ console.log("Both versions won the same number of benchmarks " +
+ "(" + wins0 + " vs. " + wins1 + ")");
+ }
+ });
});
function runSuite(suite, callback) {
- suite.on("complete", function () {
- callback();
- }).run({async: true});
+ suite.on("complete", function () {
+ callback();
+ }).run({async: true});
}
function setDefaultOptions(suiteConfig) {
- suiteConfig.args = suiteConfig.args || [[]];
- suiteConfig.setup = suiteConfig.setup || function () {};
- return suiteConfig;
+ suiteConfig.args = suiteConfig.args || [[]];
+ suiteConfig.setup = suiteConfig.setup || function () {};
+ return suiteConfig;
}
function handleMultipleArgs(list, suiteConfig) {
- return list.concat(suiteConfig.args.map(function (args) {
- return _.defaults({args: args}, suiteConfig);
- }));
+ return list.concat(suiteConfig.args.map(function (args) {
+ return _.defaults({args: args}, suiteConfig);
+ }));
}
function setName(suiteConfig) {
- suiteConfig.name = suiteConfig.name + "(" + suiteConfig.args.join(",") + ")";
- return suiteConfig;
+ suiteConfig.name = suiteConfig.name + "(" + suiteConfig.args.join(",") + ")";
+ return suiteConfig;
}
function matchesGrep(suiteConfig) {
- return !!grep.exec(suiteConfig.name);
+ return !!grep.exec(suiteConfig.name);
}
function doesNotMatch(suiteConfig) {
- return !reject.exec(suiteConfig.name);
+ return !reject.exec(suiteConfig.name);
}
function createSuite(suiteConfig) {
- var suite = new Benchmark.Suite();
- var args = suiteConfig.args;
- var errored = false;
-
- function addBench(version, versionName) {
- var name = suiteConfig.name + " " + versionName;
-
- try {
- suiteConfig.setup(1);
- suiteConfig.fn(version, function () {});
- } catch (e) {
- console.error(name + " Errored");
- errored = true;
- return;
+ var suite = new Benchmark.Suite();
+ var args = suiteConfig.args;
+ var errored = false;
+
+ function addBench(version, versionName) {
+ var name = suiteConfig.name + " " + versionName;
+
+ try {
+ suiteConfig.setup(1);
+ suiteConfig.fn(version, function () {});
+ } catch (e) {
+ console.error(name + " Errored");
+ errored = true;
+ return;
+ }
+
+ suite.add(name, function (deferred) {
+ suiteConfig.fn(version, function () {
+ deferred.resolve();
+ });
+ }, _.extend({
+ versionName: versionName,
+ setup: _.partial.apply(null, [suiteConfig.setup].concat(args)),
+ onError: function (err) {
+ console.log(err.stack);
+ }
+ }, benchOptions));
}
- suite.add(name, function (deferred) {
- suiteConfig.fn(version, function () {
- deferred.resolve();
- });
- }, _.extend({
- versionName: versionName,
- setup: _.partial.apply(null, [suiteConfig.setup].concat(args)),
- onError: function (err) {
- console.log(err.stack);
- }
- }, benchOptions));
- }
-
- addBench(versions[0], versionNames[0]);
- addBench(versions[1], versionNames[1]);
+ addBench(versions[0], versionNames[0]);
+ addBench(versions[1], versionNames[1]);
- return suite.on('cycle', function(event) {
- var mean = event.target.stats.mean * 1000;
- console.log(event.target + ", " + (+mean.toPrecision(3)) + "ms per run");
- var version = event.target.options.versionName;
- if (errored) return;
- totalTime[version] += mean;
- })
- .on('error', function (err) { console.error(err); })
+ return suite.on('cycle', function(event) {
+ var mean = event.target.stats.mean * 1000;
+ console.log(event.target + ", " + (+mean.toPrecision(3)) + "ms per run");
+ var version = event.target.options.versionName;
+ if (errored) return;
+ totalTime[version] += mean;
+ })
+ .on('error', function (err) { console.error(err); })
.on('complete', function() {
- if (!errored) {
- var fastest = this.filter('fastest');
- if (fastest.length === 2) {
- console.log("Tie");
- } else {
- var winner = fastest[0].options.versionName;
- console.log(winner + ' is faster');
- wins[winner]++;
+ if (!errored) {
+ var fastest = this.filter('fastest');
+ if (fastest.length === 2) {
+ console.log("Tie");
+ } else {
+ var winner = fastest[0].options.versionName;
+ console.log(winner + ' is faster');
+ wins[winner]++;
+ }
}
- }
- console.log("--------------------------------------");
+ console.log("--------------------------------------");
});
}
function requireVersion(tag) {
- if (tag === "current") {
- return async;
- }
+ if (tag === "current") {
+ return async;
+ }
- return require("./versions/" + tag + "/");
+ return require("./versions/" + tag + "/");
}
function cloneVersion(tag, callback) {
- if (tag === "current") return callback();
-
- var versionDir = __dirname + "/versions/" + tag;
- mkdirp.sync(versionDir);
- fs.open(versionDir + "/package.json", "r", function (err, handle) {
- if (!err) {
- // version has already been cloned
- fs.close(handle);
- return callback();
- }
+ if (tag === "current") return callback();
- var repoPath = path.join(__dirname, "..");
+ var versionDir = __dirname + "/versions/" + tag;
+ mkdirp.sync(versionDir);
+ fs.open(versionDir + "/package.json", "r", function (err, handle) {
+ if (!err) {
+ // version has already been cloned
+ fs.close(handle);
+ return callback();
+ }
- var cmd = "git clone --branch " + tag + " " + repoPath + " " + versionDir;
+ var repoPath = path.join(__dirname, "..");
- exec(cmd, function (err) {
- if (err) {
- throw err;
- }
- callback();
- });
+ var cmd = "git clone --branch " + tag + " " + repoPath + " " + versionDir;
- });
+ exec(cmd, function (err) {
+ if (err) {
+ throw err;
+ }
+ callback();
+ });
+
+ });
}
diff --git a/perf/memory.js b/perf/memory.js
index b2eaebb..1a022af 100644
--- a/perf/memory.js
+++ b/perf/memory.js
@@ -1,6 +1,6 @@
if (process.execArgv[0] !== "--expose-gc") {
- console.error("please run with node --expose-gc");
- process.exit(1);
+ console.error("please run with node --expose-gc");
+ process.exit(1);
}
var async = require("../");
@@ -8,39 +8,39 @@ global.gc();
var startMem = process.memoryUsage().heapUsed;
function waterfallTest(cb) {
- var functions = [];
-
- for(var i = 0; i < 10000; i++) {
- functions.push(function leaky(next) {
- function func1(cb) {return cb(); }
-
- function func2(callback) {
- if (true) {
- callback();
- //return next(); // Should be callback here.
- }
- }
-
- function func3(cb) {return cb(); }
-
- async.waterfall([
- func1,
- func2,
- func3
- ], next);
- });
- }
-
- async.parallel(functions, cb);
+ var functions = [];
+
+ for(var i = 0; i < 10000; i++) {
+ functions.push(function leaky(next) {
+ function func1(cb) {return cb(); }
+
+ function func2(callback) {
+ if (true) {
+ callback();
+ //return next(); // Should be callback here.
+ }
+ }
+
+ function func3(cb) {return cb(); }
+
+ async.waterfall([
+ func1,
+ func2,
+ func3
+ ], next);
+ });
+ }
+
+ async.parallel(functions, cb);
}
function reportMemory() {
- global.gc();
- var increase = process.memoryUsage().heapUsed - startMem;
- console.log("memory increase: " +
- (+(increase / 1024).toPrecision(3)) + "kB");
+ global.gc();
+ var increase = process.memoryUsage().heapUsed - startMem;
+ console.log("memory increase: " +
+ (+(increase / 1024).toPrecision(3)) + "kB");
}
waterfallTest(function () {
- setTimeout(reportMemory, 0);
+ setTimeout(reportMemory, 0);
});
diff --git a/perf/suites.js b/perf/suites.js
index 42611db..dd8392c 100644
--- a/perf/suites.js
+++ b/perf/suites.js
@@ -3,295 +3,295 @@ var tasks;
module.exports = [
{
- name: "each",
- // args lists are passed to the setup function
- args: [[10], [300], [10000]],
- setup: function(count) {
- tasks = _.range(count);
- },
- fn: function (async, done) {
- async.each(tasks, function (num, cb) {
- async.setImmediate(cb);
- }, done);
- }
+ name: "each",
+ // args lists are passed to the setup function
+ args: [[10], [300], [10000]],
+ setup: function(count) {
+ tasks = _.range(count);
+ },
+ fn: function (async, done) {
+ async.each(tasks, function (num, cb) {
+ async.setImmediate(cb);
+ }, done);
+ }
},
{
- name: "eachSeries",
- args: [[10], [300], [10000]],
- setup: function(count) {
- tasks = _.range(count);
- },
- fn: function (async, done) {
- async.eachSeries(tasks, function (num, cb) {
- async.setImmediate(cb);
- }, done);
- }
+ name: "eachSeries",
+ args: [[10], [300], [10000]],
+ setup: function(count) {
+ tasks = _.range(count);
+ },
+ fn: function (async, done) {
+ async.eachSeries(tasks, function (num, cb) {
+ async.setImmediate(cb);
+ }, done);
+ }
},
{
- name: "eachLimit",
- args: [[10], [300], [10000]],
- setup: function(count) {
- tasks = _.range(count);
- },
- fn: function (async, done) {
- async.eachLimit(tasks, 4, function (num, cb) {
- async.setImmediate(cb);
- }, done);
- }
+ name: "eachLimit",
+ args: [[10], [300], [10000]],
+ setup: function(count) {
+ tasks = _.range(count);
+ },
+ fn: function (async, done) {
+ async.eachLimit(tasks, 4, function (num, cb) {
+ async.setImmediate(cb);
+ }, done);
+ }
},
{
- name: "map",
- // args lists are passed to the setup function
- args: [[10], [300], [10000]],
- setup: function(count) {
- tasks = _.range(count);
- },
- fn: function (async, done) {
- async.map(tasks, function (num, cb) {
- async.setImmediate(cb);
- }, done);
- }
+ name: "map",
+ // args lists are passed to the setup function
+ args: [[10], [300], [10000]],
+ setup: function(count) {
+ tasks = _.range(count);
+ },
+ fn: function (async, done) {
+ async.map(tasks, function (num, cb) {
+ async.setImmediate(cb);
+ }, done);
+ }
},
{
- name: "mapSeries",
- args: [[10], [300], [10000]],
- setup: function(count) {
- tasks = _.range(count);
- },
- fn: function (async, done) {
- async.mapSeries(tasks, function (num, cb) {
- async.setImmediate(cb);
- }, done);
- }
+ name: "mapSeries",
+ args: [[10], [300], [10000]],
+ setup: function(count) {
+ tasks = _.range(count);
+ },
+ fn: function (async, done) {
+ async.mapSeries(tasks, function (num, cb) {
+ async.setImmediate(cb);
+ }, done);
+ }
},
{
- name: "mapLimit",
- args: [[10], [300], [10000]],
- setup: function(count) {
- tasks = _.range(count);
- },
- fn: function (async, done) {
- async.mapLimit(tasks, 4, function (num, cb) {
- async.setImmediate(cb);
- }, done);
- }
+ name: "mapLimit",
+ args: [[10], [300], [10000]],
+ setup: function(count) {
+ tasks = _.range(count);
+ },
+ fn: function (async, done) {
+ async.mapLimit(tasks, 4, function (num, cb) {
+ async.setImmediate(cb);
+ }, done);
+ }
},
{
- name: "eachOf",
- // args lists are passed to the setup function
- args: [[10], [300], [10000]],
- setup: function(count) {
- tasks = _.range(count);
- },
- fn: function (async, done) {
- async.eachOf(tasks, function (num, i, cb) {
- async.setImmediate(cb);
- }, done);
- }
+ name: "eachOf",
+ // args lists are passed to the setup function
+ args: [[10], [300], [10000]],
+ setup: function(count) {
+ tasks = _.range(count);
+ },
+ fn: function (async, done) {
+ async.eachOf(tasks, function (num, i, cb) {
+ async.setImmediate(cb);
+ }, done);
+ }
},
{
- name: "eachOfSeries",
- args: [[10], [300], [10000]],
- setup: function(count) {
- tasks = _.range(count);
- },
- fn: function (async, done) {
- async.eachOfSeries(tasks, function (num, i, cb) {
- async.setImmediate(cb);
- }, done);
- }
+ name: "eachOfSeries",
+ args: [[10], [300], [10000]],
+ setup: function(count) {
+ tasks = _.range(count);
+ },
+ fn: function (async, done) {
+ async.eachOfSeries(tasks, function (num, i, cb) {
+ async.setImmediate(cb);
+ }, done);
+ }
},
{
- name: "eachOfLimit",
- args: [[10], [300], [10000]],
- setup: function(count) {
- tasks = _.range(count);
- },
- fn: function (async, done) {
- async.eachOfLimit(tasks, 4, function (num, i, cb) {
- async.setImmediate(cb);
- }, done);
- }
+ name: "eachOfLimit",
+ args: [[10], [300], [10000]],
+ setup: function(count) {
+ tasks = _.range(count);
+ },
+ fn: function (async, done) {
+ async.eachOfLimit(tasks, 4, function (num, i, cb) {
+ async.setImmediate(cb);
+ }, done);
+ }
},
{
- name: "parallel",
- args: [[10], [100], [1000]],
- setup: function (count) {
- tasks = _.range(count).map(function () {
- return function (cb) {
- setImmediate(cb);
- };
- });
- },
- fn: function (async, done) {
- async.parallel(tasks, done);
- }
+ name: "parallel",
+ args: [[10], [100], [1000]],
+ setup: function (count) {
+ tasks = _.range(count).map(function () {
+ return function (cb) {
+ setImmediate(cb);
+ };
+ });
+ },
+ fn: function (async, done) {
+ async.parallel(tasks, done);
+ }
},
{
- name: "series",
- args: [[10], [100], [1000]],
- setup: function (count) {
- tasks = _.range(count).map(function () {
- return function (cb) { setImmediate(cb); };
- });
- },
- fn: function (async, done) {
- async.series(tasks, done);
- }
+ name: "series",
+ args: [[10], [100], [1000]],
+ setup: function (count) {
+ tasks = _.range(count).map(function () {
+ return function (cb) { setImmediate(cb); };
+ });
+ },
+ fn: function (async, done) {
+ async.series(tasks, done);
+ }
},
{
- name: "waterfall",
- args: [[10], [100], [1000]],
- setup: function (count) {
- tasks = [
+ name: "waterfall",
+ args: [[10], [100], [1000]],
+ setup: function (count) {
+ tasks = [
function (cb) {
- return cb(null, 1);
+ return cb(null, 1);
}
].concat(_.range(count).map(function (i) {
- return function (arg, cb) {
- setImmediate(function () {
- cb(null, i);
- });
- };
+ return function (arg, cb) {
+ setImmediate(function () {
+ cb(null, i);
+ });
+ };
}));
- },
- fn: function (async, done) {
- async.waterfall(tasks, done);
- }
+ },
+ fn: function (async, done) {
+ async.waterfall(tasks, done);
+ }
},
{
- name: "queue",
- args: [[1000], [30000], [100000], [200000]],
- setup: function (count) {
- tasks = count;
- },
- fn: function (async, done) {
- var numEntries = tasks;
- var q = async.queue(worker, 1);
- for (var i = 1; i <= numEntries; i++) {
- q.push({num: i});
- }
- function worker(task, callback) {
- if (task.num === numEntries) {
- return done();
- }
- setImmediate(callback);
+ name: "queue",
+ args: [[1000], [30000], [100000], [200000]],
+ setup: function (count) {
+ tasks = count;
+ },
+ fn: function (async, done) {
+ var numEntries = tasks;
+ var q = async.queue(worker, 1);
+ for (var i = 1; i <= numEntries; i++) {
+ q.push({num: i});
+ }
+ function worker(task, callback) {
+ if (task.num === numEntries) {
+ return done();
+ }
+ setImmediate(callback);
+ }
}
- }
},
{
- name: "some - no short circuit- false",
- // args lists are passed to the setup function
- args: [[500]],
- setup: function(count) {
- tasks = _.range(count);
- },
- fn: function (async, done) {
- async.some(tasks, function(i, cb) {
- async.setImmediate(function() {
- cb(i >= 600);
- });
- }, done);
- }
+ name: "some - no short circuit- false",
+ // args lists are passed to the setup function
+ args: [[500]],
+ setup: function(count) {
+ tasks = _.range(count);
+ },
+ fn: function (async, done) {
+ async.some(tasks, function(i, cb) {
+ async.setImmediate(function() {
+ cb(i >= 600);
+ });
+ }, done);
+ }
},
{
- name: "some - short circuit - true",
- // args lists are passed to the setup function
- args: [[500]],
- setup: function(count) {
- tasks = _.range(count);
- },
- fn: function (async, done) {
- async.some(tasks, function(i, cb) {
- async.setImmediate(function() {
- cb(i >= 60);
- });
- }, done);
- }
+ name: "some - short circuit - true",
+ // args lists are passed to the setup function
+ args: [[500]],
+ setup: function(count) {
+ tasks = _.range(count);
+ },
+ fn: function (async, done) {
+ async.some(tasks, function(i, cb) {
+ async.setImmediate(function() {
+ cb(i >= 60);
+ });
+ }, done);
+ }
},
{
- name: "every - no short circuit- true",
- // args lists are passed to the setup function
- args: [[500]],
- setup: function(count) {
- tasks = _.range(count);
- },
- fn: function (async, done) {
- async.every(tasks, function(i, cb) {
- async.setImmediate(function() {
- cb(i <= 600);
- });
- }, done);
- }
+ name: "every - no short circuit- true",
+ // args lists are passed to the setup function
+ args: [[500]],
+ setup: function(count) {
+ tasks = _.range(count);
+ },
+ fn: function (async, done) {
+ async.every(tasks, function(i, cb) {
+ async.setImmediate(function() {
+ cb(i <= 600);
+ });
+ }, done);
+ }
},
{
- name: "every - short circuit - false",
- // args lists are passed to the setup function
- args: [[500]],
- setup: function(count) {
- tasks = _.range(count);
- },
- fn: function (async, done) {
- async.every(tasks, function(i, cb) {
- async.setImmediate(function() {
- cb(i <= 60);
- });
- }, done);
- }
+ name: "every - short circuit - false",
+ // args lists are passed to the setup function
+ args: [[500]],
+ setup: function(count) {
+ tasks = _.range(count);
+ },
+ fn: function (async, done) {
+ async.every(tasks, function(i, cb) {
+ async.setImmediate(function() {
+ cb(i <= 60);
+ });
+ }, done);
+ }
},
{
- name: "defer nextTick",
- fn: function (async, done) {
- process.nextTick(done);
- }
+ name: "defer nextTick",
+ fn: function (async, done) {
+ process.nextTick(done);
+ }
},
{
- name: "defer setImmediate",
- fn: function (async, done) {
- setImmediate(done);
- }
+ name: "defer setImmediate",
+ fn: function (async, done) {
+ setImmediate(done);
+ }
},
{
- name: "defer async.nextTick",
- fn: function (async, done) {
- async.nextTick(done);
- }
+ name: "defer async.nextTick",
+ fn: function (async, done) {
+ async.nextTick(done);
+ }
},
{
- name: "defer async.setImmediate",
- fn: function (async, done) {
- async.setImmediate(done);
- }
+ name: "defer async.setImmediate",
+ fn: function (async, done) {
+ async.setImmediate(done);
+ }
},
{
- name: "defer setTimeout",
- fn: function (async, done) {
- setTimeout(done, 0);
- }
+ name: "defer setTimeout",
+ fn: function (async, done) {
+ setTimeout(done, 0);
+ }
},
{
- name: "ensureAsync sync",
- fn: function (async, done) {
- async.ensureAsync(function (cb) {
- cb();
- })(done);
- }
+ name: "ensureAsync sync",
+ fn: function (async, done) {
+ async.ensureAsync(function (cb) {
+ cb();
+ })(done);
+ }
},
{
- name: "ensureAsync async",
- fn: function (async, done) {
- async.ensureAsync(function (cb) {
- setImmediate(cb);
- })(done);
- }
+ name: "ensureAsync async",
+ fn: function (async, done) {
+ async.ensureAsync(function (cb) {
+ setImmediate(cb);
+ })(done);
+ }
},
{
- name: "ensureAsync async noWrap",
- fn: function (async, done) {
- (function (cb) {
- setImmediate(cb);
- }(done));
- }
+ name: "ensureAsync async noWrap",
+ fn: function (async, done) {
+ (function (cb) {
+ setImmediate(cb);
+ }(done));
+ }
}
];