Skip to content

Commit 2554a3b

Browse files
Simplify benchmark by using more low-level API from 'benchmark.js' (#1750)
1 parent 7786a25 commit 2554a3b

File tree

1 file changed

+14
-26
lines changed

1 file changed

+14
-26
lines changed

resources/benchmark.js

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
'use strict';
1111

12-
const { Suite } = require('benchmark');
12+
const { Benchmark } = require('benchmark');
1313
const { execSync } = require('child_process');
1414
const os = require('os');
1515
const fs = require('fs');
@@ -79,33 +79,21 @@ function findFiles(cwd, pattern) {
7979

8080
// Run a given benchmark test with the provided revisions.
8181
function runBenchmark(benchmark, environments) {
82-
const modules = environments.map(({ distPath }) =>
83-
require(path.join(distPath, benchmark))
84-
);
85-
const benchResults = []
86-
87-
const suite = new Suite(modules[0].name, {
88-
onStart(event) {
89-
console.log('⏱️ ' + event.currentTarget.name);
90-
},
91-
onCycle({ target }) {
92-
benchResults.push(target);
93-
process.stdout.write(
94-
' ' + cyan(benchResults.length) + ' tests completed.\u000D',
95-
);
96-
},
97-
onError(event) {
98-
console.error(event.target.error);
99-
},
100-
onComplete() {
101-
console.log('\n');
102-
beautifyBenchmark(benchResults);
103-
},
82+
let benchmarkName;
83+
const benches = environments.map(environment => {
84+
const module = require(path.join(environment.distPath, benchmark))
85+
benchmarkName = module.name;
86+
return new Benchmark(environment.revision, module.measure);
10487
});
105-
for (let i = 0; i < environments.length; i++) {
106-
suite.add(environments[i].revision, modules[i].measure);
88+
89+
console.log('⏱️ ' + benchmarkName);
90+
for (let i = 0; i < benches.length; ++i) {
91+
benches[i].run({ async: false });
92+
process.stdout.write(' ' + cyan(i + 1) + ' tests completed.\u000D');
10793
}
108-
suite.run({ async: false });
94+
console.log('\n');
95+
96+
beautifyBenchmark(benches);
10997
console.log('');
11098
}
11199

0 commit comments

Comments
 (0)