-
Notifications
You must be signed in to change notification settings - Fork 26
/
runBenchmark.ts
39 lines (31 loc) · 970 Bytes
/
runBenchmark.ts
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
const path = require('path');
const walker = require('walker');
const Suite = require('benchmark').Suite;
function createSuite(name, tests) {
const suite = new Suite(name);
for (const key in tests) {
suite.add(key, tests[key]);
}
console.log(`${name}:`);
return suite
.on('cycle', (event) => {
console.log(String(event.target));
})
.on('complete', () => {
console.log('_________________\n');
});
}
const filterRegex = process.argv[2] ? new RegExp(process.argv[2]) : null;
walker(path.resolve(__dirname, 'src'))
.filterDir((dir) => {
return !/node_modules/.test(dir);
})
.on('file', (file) => {
if (filterRegex && !filterRegex.test(file)) {
return;
}
if (/__benchmarks__/.test(file)) {
const tests = require(file).default;
createSuite(path.relative(__dirname, file), tests).run();
}
});