forked from domvm/domvm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
66 lines (57 loc) · 1.89 KB
/
index.js
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
"use strict";
const benchmark = require('benchmark'),
cliff = require('cliff'),
fs = require('fs'),
suits = {
renderToString : require('./renderToString')
},
versions = JSON.parse(fs.readFileSync(__dirname + '/package.json', 'utf8')).dependencies;
let results;
Object.keys(suits).forEach(suitName => {
const suite = new benchmark.Suite(
suitName,
{
onStart() {
results = [];
console.log(`Starts suit "${suitName}"`);
},
onComplete() {
console.log('\n' + cliff.stringifyObjectRows(
results.sort((resultA, resultB) => resultA.mean - resultB.mean),
['', 'mean time', 'ops/sec'],
['', 'green', 'yellow']) + '\n');
}
}),
test = suits[suitName];
Object.keys(test).forEach(testName => {
let i = 0,
name = ` ${testName} v${versions[testName.indexOf('.') > -1? testName.split('.')[0] : testName]} `,
testFn = test[testName],
defer = !!testFn.length;
suite.add(
testName,
defer?
deferred => {
testFn(deferred);
} :
testFn,
{
defer,
onStart() {
console.log(`${name}`);
},
onCycle() {
console.log(`\x1B[1A${name}` + new Array(i++).join('.'));
},
onComplete() {
results.push({
'' : name,
mean : this.stats.mean,
'mean time' : (this.stats.mean * 1000).toFixed(3) + 'ms',
'ops/sec' : (1 / this.stats.mean).toFixed(0)
});
}
});
});
suite.run();
});