public
Last active

Zen vs Stack vs Stack2

  • Download Gist
bench.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
var STACKSIZE=1;
 
var zen=require('zen');
var stack=require('stack');
var stack2=require('stack2');
 
var mod=function(a,b,next){next();}
var middles=[];
for (var i=0;i<STACKSIZE;i++){
middles.push(mod);
}
 
var errorHandler=function(a,b,err){
return;
}
 
var zenApp=zen.apply(this,middles);
zenApp.errorHandler=errorHandler;
 
stack.errorHandler=errorHandler;
var stackApp=stack.apply(this,middles);
 
stack2.errorHandler=errorHandler;
var stack2App=stack2.apply(this,middles);
 
var Benchmark = require('benchmark');
 
var suite = new Benchmark.Suite;
 
// add tests
suite.add('Zen', function() {
zenApp(null,null);
})
.add('Stack', function() {
stackApp(null,null);
})
.add('Stack2', function() {
stack2App(null,null);
})
// add listeners
.on('cycle', function(bench) {
console.log(String(bench));
})
.on('complete', function() {
console.log('Fastest is ' + this.filter('fastest').pluck('name'));
})
// run async
.run(true);
result
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
STACKSIZE=1
$ node bench.js
Zen x 351,228 ops/sec ±7.00% (65 runs sampled)
Stack x 2,423,546 ops/sec ±1.73% (74 runs sampled)
Stack2 x 1,611,787 ops/sec ±3.07% (68 runs sampled)
Fastest is Stack
 
STACKSIZE=25
$ node bench.js
Zen x 14,993 ops/sec ±6.65% (68 runs sampled)
Stack x 109,575 ops/sec ±1.78% (76 runs sampled)
Stack2 x 78,496 ops/sec ±1.69% (75 runs sampled)
Fastest is Stack
 
STACKSIZE=50
$ node bench.js
Zen x 8,395 ops/sec ±1.60% (76 runs sampled)
Stack x 53,659 ops/sec ±1.77% (75 runs sampled)
Stack2 x 35,124 ops/sec ±1.38% (71 runs sampled)
Fastest is Stack
 
STACKSIZE=500
$ node bench.js
Zen x 770 ops/sec ±4.75% (71 runs sampled)
Stack x 4,043 ops/sec ±8.91% (62 runs sampled)
Stack2 x 43.34 ops/sec ±6.97% (41 runs sampled)
Fastest is Stack
 
STACKSIZE=1000
$node bench.js
Zen x 400 ops/sec ±3.80% (74 runs sampled)
Stack x 2,437 ops/sec ±1.93% (75 runs sampled)
Stack2 x 5.34 ops/sec ±16.08% (6 runs sampled)
Fastest is Stack

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.