Skip to content

Commit e584c58

Browse files
committed
add benchmark
1 parent 4cf945f commit e584c58

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
},
2727
"devDependencies": {
2828
"autod": "*",
29+
"beautify-benchmark": "~0.2.4",
30+
"benchmark": "~1.0.0",
2931
"istanbul": "*",
3032
"mocha": "*",
3133
"should": "*"

test/benchmark/ms.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/**!
2+
* humanize-ms - test/benchmark/ms.js
3+
*
4+
* Copyright(c) node-modules and other contributors.
5+
* MIT Licensed
6+
*
7+
* Authors:
8+
* fengmk2 <[email protected]> (http://fengmk2.com)
9+
*/
10+
11+
'use strict';
12+
13+
/**
14+
* Module dependencies.
15+
*/
16+
17+
var Benchmark = require('benchmark');
18+
var benchmarks = require('beautify-benchmark');
19+
var originMS = require('ms');
20+
var ms = require('../..');
21+
22+
var suite = new Benchmark.Suite();
23+
24+
// add tests
25+
suite
26+
27+
.add('origin ms()', function() {
28+
originMS('10s');
29+
})
30+
.add('ms()', function() {
31+
ms('10s');
32+
})
33+
.add('ms(1000)', function() {
34+
ms(1000);
35+
})
36+
37+
// add listeners
38+
.on('cycle', function (event) {
39+
benchmarks.add(event.target);
40+
})
41+
.on('start', function () {
42+
console.log('\n node version: %s, date: %s\n Starting...', process.version, Date());
43+
})
44+
.on('complete', function() {
45+
benchmarks.log();
46+
})
47+
// run async
48+
.run({ 'async': false });
49+
50+
// node version: v1.6.3, date: Mon Apr 06 2015 11:59:04 GMT+0800 (CST)
51+
// Starting...
52+
// 3 tests completed.
53+
//
54+
// origin ms() x 3,393,695 ops/sec ±1.30% (92 runs sampled)
55+
// ms() x 3,430,360 ops/sec ±1.05% (90 runs sampled)
56+
// ms(1000) x 94,272,966 ops/sec ±1.11% (93 runs sampled)

0 commit comments

Comments
 (0)