Skip to content

Commit

Permalink
add benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
fengmk2 committed Apr 6, 2015
1 parent 4cf945f commit e584c58
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
},
"devDependencies": {
"autod": "*",
"beautify-benchmark": "~0.2.4",
"benchmark": "~1.0.0",
"istanbul": "*",
"mocha": "*",
"should": "*"
Expand Down
56 changes: 56 additions & 0 deletions test/benchmark/ms.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/**!
* humanize-ms - test/benchmark/ms.js
*
* Copyright(c) node-modules and other contributors.
* MIT Licensed
*
* Authors:
* fengmk2 <[email protected]> (http://fengmk2.com)
*/

'use strict';

/**
* Module dependencies.
*/

var Benchmark = require('benchmark');
var benchmarks = require('beautify-benchmark');
var originMS = require('ms');
var ms = require('../..');

var suite = new Benchmark.Suite();

// add tests
suite

.add('origin ms()', function() {
originMS('10s');
})
.add('ms()', function() {
ms('10s');
})
.add('ms(1000)', function() {
ms(1000);
})

// add listeners
.on('cycle', function (event) {
benchmarks.add(event.target);
})
.on('start', function () {
console.log('\n node version: %s, date: %s\n Starting...', process.version, Date());
})
.on('complete', function() {
benchmarks.log();
})
// run async
.run({ 'async': false });

// node version: v1.6.3, date: Mon Apr 06 2015 11:59:04 GMT+0800 (CST)
// Starting...
// 3 tests completed.
//
// origin ms() x 3,393,695 ops/sec ±1.30% (92 runs sampled)
// ms() x 3,430,360 ops/sec ±1.05% (90 runs sampled)
// ms(1000) x 94,272,966 ops/sec ±1.11% (93 runs sampled)

0 comments on commit e584c58

Please sign in to comment.