Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
async-benchmark.js
/*
Usage:
$ node async-benchmark.js -t 999999
*/
var parallelly = require("parallelly");
var serially = require("serially");
var async = require("async");
var time = require("measure-time");
var map = require("map");
var parallelLoop = require("parallel-loop");
var serialLoop = require("serial-loop");
var limitedParallelLoop = require("limited-parallel-loop");
time('parallely', function (end) {
parallelly()
.then(foo)
.then(bar)
.then(qux)
.done(end);
});
time('async.parallel', function (end) {
async.parallel([
foo, bar, qux
], end);
});
time('serially', function (end) {
serially()
.then(foo)
.then(bar)
.then(qux)
.done(end);
});
time('async.series', function (end) {
async.series([
foo, bar, qux
], end);
});
time('map (parallel)', function (end) {
map.parallel(corge, [1, 2, 3, 4, 5], end);
});
time('async.map', function (end) {
map.parallel(corge, [1, 2, 3, 4, 5], end);
});
time('map (serial)', function (end) {
map.parallel(corge, [1, 2, 3, 4, 5], end);
});
time('async.mapSeries', function (end) {
map.parallel(corge, [1, 2, 3, 4, 5], end);
});
time('parallel-loop', function (end) {
var arr = [1, 2, 3, 4, 5];
parallelLoop(arr.length, function (done) {
setImmediate(done);
}, end);
});
time('async.each', function (end) {
async.each([1, 2, 3, 4, 5], function (_, done) {
setImmediate(done);
}, end);
});
time('serial-loop', function (end) {
var arr = [1, 2, 3, 4, 5];
serialLoop(arr.length, function (done) {
setImmediate(done);
}, end);
});
time('async.eachSeries', function (end) {
async.eachSeries([1, 2, 3, 4, 5], function (_, done) {
setImmediate(done);
}, end);
});
time('parallel-limited-loop', function (end) {
var arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13];
limitedParallelLoop(arr.length, 3, function (done) {
setImmediate(done);
}, end);
});
time('async.eachLimit', function (end) {
async.eachLimit([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13], 3, function (_, done) {
setImmediate(done);
}, end);
});
function foo (callback) {
process.nextTick(function () {
callback(undefined, 1);
});
}
function bar (callback) {
process.nextTick(function () {
callback(undefined, 2);
});
}
function qux (callback) {
process.nextTick(function () {
callback(undefined, 3);
});
}
function corge (_, callback) {
process.nextTick(function () {
callback(undefined, 3);
});
}
@talkingtab

This comment has been minimized.

Copy link

@talkingtab talkingtab commented Aug 25, 2014

I'm assuming that lines 50, 54 and 58 are all cut and paste errors?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment