forked from umijs/umi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbenchmarks.js
More file actions
41 lines (37 loc) · 1.08 KB
/
benchmarks.js
File metadata and controls
41 lines (37 loc) · 1.08 KB
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
const path = require('path');
const Benchmark = require('benchmark');
const { glob } = require('@umijs/utils');
const buildExamples = require('./buildExamples');
// benchmarks entry
const bootstrap = async () => {
const benchmarks = glob.sync('examples/*/benchmark.js', {
dot: false,
absolute: true,
cwd: path.join(__dirname, '..'),
});
const projects = benchmarks.map((benchmark) => path.dirname(benchmark));
await buildExamples(projects);
const suite = new Benchmark.Suite();
benchmarks.forEach((benchmark) => {
const benchmarkFunc = require(benchmark);
benchmarkFunc(suite);
});
suite
.on('cycle', function (event) {
console.log(String(event.target));
})
.on('complete', function () {
console.log('');
for (let index = 0; index < this.length; index++) {
const benchmark = this[index];
console.log(benchmark.name);
console.log(
`Mean: ${Math.round(benchmark.stats.mean * 1000 * 1000)} ms`,
);
console.log('');
}
})
// run async
.run({ async: true });
};
bootstrap();