Neo-Async
Neo-Async is thought to be used as a drop-in replacement for Async, it almost fully covers its functionality and runs faster
Speed Comparison
- async v0.9.0
- neo-async v0.4.9
Front-end
Speed comparison of front-end measured by jsPerf.
Measurement environment are as follows.
- Chrome 40.0.2214
- FireFox 34.0
- Safari 8.0.2
figure 1: waterfall sample
The value is the ratio (Neo-Async/Async) of the executions numbers per second.
Server-side
Speed comparison of server-side measured by func-comparator.
Specifications are as follows.
- n times trials
- Random execution order
- Execute GC every time
- Measure the average speed[μs] of n times
demo.js
var comparator = require('func-comparator');
var _ = require('lodash');
var async = require('async');
var neo_async = require('neo-async');
var count = 10;
var n = 1000;
var array = _.shuffle(_.times(count));
var tasks = _.map(array, function(n) {
return function(next) {
next(null, n);
};
});
var funcs = {
'async': function(callback) {
async.parallel(tasks, callback);
},
'neo-async': function(callback) {
neo_async.parallel(tasks, callback);
}
};
comparator
.set(funcs)
.option({
async: true,
times: n
})
.start()
.result(console.log);
execute
- 10 times trials
- 1000 tasks
Execution environment are as follows.
$ node --expose_gc demo.js
$ iojs --expose_gc demo.js
result
The value is the ratio (Async/Neo-Async) of the average speed per n times.
function | node | iojs |
---|
waterfall | 3.47 | 12.05 |
series | 1.98 | 6.38 |
parallel | 2.94 | 8.94 |
paralellLimit | 2.88 | 6.13 |
The results show that we could improve perfomance by using either node or iojs.
Waterfall
A test to examine the relation between perfomance and number of tasks.
- Execute tasks from lower to upper in the specified interval
- Random execution order
- Execute gc every time
- Measure the average speed[μs] of n times
demo2.js
var statistic = require('func-comparator').statistic;
var _ = require('lodash');
var async = require('async');
var neo_async = require('neo-async');
var n = 100;
var create = function(count) {
var array = _.shuffle(_.times(count));
var tasks = _.map(array, function(n, i) {
if (i === 0) {
return function(next) {
next(null, n);
};
}
return function(total, next) {
next(null, total + n);
};
});
var funcs = {
'async': function(callback) {
async.waterfall(tasks, callback);
},
'neo-async': function(callback) {
neo_async.waterfall(tasks, callback);
}
};
return funcs;
};
statistic
.create(create)
.option({
async: true,
times: n,
count: {
lower: 10,
upper: 1000,
interval: 10
}
})
.start()
.result(console.log)
.csv('waterfall_' + _.now());
execute
- lower: 10
- upper: 1000
- interval: 10
- sampling number: 100
Test environment are as follows.
$ node --expose_gc demo2.js
$ iojs --expose_gc demo2.js
result
Test result are in the following figure.
- x-axis: number of tasks
- y-axis: average times[μs]
figure 2: speed comparison of node
figure 3: speed comparison of iojs
Neo-Async will be expected to have high performance if we are working with large numbers of tasks.
Improvement of convenience
neo-async also have loop support for Object which is unsupported in async.
var object = {
HOGE: 'hoge',
FUGA: 'fuga',
PIYO: 'piyo'
};
async.each(Object.keys(object), function(key, done) {
var str = object[key];
done();
}, callback);
neo_async.each(object, function(str, done) {
done();
}, callback, thisArg);
Installation
In a browser
<script src="async.min.js"></script>
In an AMD loader
require(['async'], function(async) {});
Node.js
standard
$ npm install neo-async
var async = require('neo-async');
replacement
$ npm install neo-async
$ ln -s ./node_modules/neo-async ./node_modules/async
var async = require('async');
Feature not in Async
Collections
Control Flow
Utils