Created
August 24, 2014 16:11
-
-
Save hengkiardo/f3c68d6ec81a0ebc9073 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment