Created
August 23, 2014 16:20
-
-
Save dead-horse/731eb86a684e2f1bd368 to your computer and use it in GitHub Desktop.
co benchmark for thunk and promise
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
var benchmarks = require('beautify-benchmark'); | |
var Benchmark = require('benchmark'); | |
var thunkify = require('thunkify'); | |
var zlib = require('zlib'); | |
var co = require('co'); | |
var fs = require('fs'); | |
var gzipPromise = require('mz/zlib').gzip; | |
var gzipThunk = thunkify(zlib.gzip); | |
var fsPromise = require('mz/fs'); | |
var fsThunk = require('co-fs'); | |
var suite = new Benchmark.Suite(); | |
var file = require('path').join(__dirname, 'package.json'); | |
var content = fs.readFileSync(file); | |
suite | |
.add('promise fs.stat', function () { | |
co(function* () { | |
yield fsPromise.stat(file) | |
})(); | |
}) | |
.add('thunk fs.stat', function () { | |
co(function* () { | |
yield fsThunk.stat(file) | |
})(); | |
}) | |
.add('promise fs.exists', function () { | |
co(function* () { | |
yield fsPromise.exists(file) | |
})(); | |
}) | |
.add('thunk fs.exists', function () { | |
co(function* () { | |
yield fsThunk.exists(file) | |
})(); | |
}) | |
.add('promise gzip', function () { | |
co(function* () { | |
yield gzipPromise(content); | |
})(); | |
}) | |
.add('thunk gzip', function () { | |
co(function* () { | |
yield gzipThunk(content); | |
})(); | |
}) | |
.on('cycle', function(event) { | |
benchmarks.add(event.target); | |
}) | |
.on('start', function(event) { | |
console.log('\n node version: %s, date: %s\n Starting...', process.version, Date()); | |
}) | |
.on('complete', function done() { | |
benchmarks.log(); | |
}) | |
.run({ 'async': true }); | |
// with bluebird | |
// node version: v0.11.13, date: Sun Aug 24 2014 00:18:24 GMT+0800 (CST) | |
// Starting... | |
// 6 tests completed. | |
// promise fs.stat x 85,529 ops/sec ±3.31% (72 runs sampled) | |
// thunk fs.stat x 100,951 ops/sec ±3.05% (74 runs sampled) | |
// promise fs.exists x 93,367 ops/sec ±2.59% (80 runs sampled) | |
// thunk fs.exists x 121,395 ops/sec ±2.75% (75 runs sampled) | |
// promise gzip x 16,335 ops/sec ±4.46% (76 runs sampled) | |
// thunk gzip x 17,321 ops/sec ±4.44% (81 runs sampled) | |
// with native promise | |
// node version: v0.11.13, date: Sun Aug 24 2014 00:14:06 GMT+0800 (CST) | |
// Starting... | |
// 6 tests completed. | |
// promise fs.stat x 67,484 ops/sec ±2.98% (78 runs sampled) | |
// thunk fs.stat x 100,174 ops/sec ±2.92% (81 runs sampled) | |
// promise fs.exists x 74,958 ops/sec ±3.16% (80 runs sampled) | |
// thunk fs.exists x 116,378 ops/sec ±2.76% (76 runs sampled) | |
// promise gzip x 15,609 ops/sec ±4.73% (68 runs sampled) | |
// thunk gzip x 18,871 ops/sec ±3.96% (73 runs sampled) |
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
{ | |
"name": "co-bench", | |
"version": "0.0.0", | |
"description": "co bench for promise and thunk", | |
"main": "bench.js", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"author": "dead_horse <[email protected]>", | |
"license": "MIT", | |
"devDependencies": { | |
"beautify-benchmark": "~0.2.4", | |
"benchmark": "~1.0.0", | |
"bluebird": "~2.3.1", | |
"co": "~3.1.0", | |
"co-fs": "~1.2.0", | |
"mz": "~1.0.1", | |
"thunkify": "~2.1.2" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment