Skip to content

Simplify benchmark by using more low-level API from 'benchmark.js' #1750

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 20, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 14 additions & 26 deletions resources/benchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

'use strict';

const { Suite } = require('benchmark');
const { Benchmark } = require('benchmark');
const { execSync } = require('child_process');
const os = require('os');
const fs = require('fs');
Expand Down Expand Up @@ -79,33 +79,21 @@ function findFiles(cwd, pattern) {

// Run a given benchmark test with the provided revisions.
function runBenchmark(benchmark, environments) {
const modules = environments.map(({ distPath }) =>
require(path.join(distPath, benchmark))
);
const benchResults = []

const suite = new Suite(modules[0].name, {
onStart(event) {
console.log('⏱️ ' + event.currentTarget.name);
},
onCycle({ target }) {
benchResults.push(target);
process.stdout.write(
' ' + cyan(benchResults.length) + ' tests completed.\u000D',
);
},
onError(event) {
console.error(event.target.error);
},
onComplete() {
console.log('\n');
beautifyBenchmark(benchResults);
},
let benchmarkName;
const benches = environments.map(environment => {
const module = require(path.join(environment.distPath, benchmark))
benchmarkName = module.name;
return new Benchmark(environment.revision, module.measure);
});
for (let i = 0; i < environments.length; i++) {
suite.add(environments[i].revision, modules[i].measure);

console.log('⏱️ ' + benchmarkName);
for (let i = 0; i < benches.length; ++i) {
benches[i].run({ async: false });
process.stdout.write(' ' + cyan(i + 1) + ' tests completed.\u000D');
}
suite.run({ async: false });
console.log('\n');

beautifyBenchmark(benches);
console.log('');
}

Expand Down