|
|
|
|
@ -11,12 +11,17 @@ import { fileURLToPath } from 'node:url';
|
|
|
|
|
const filename = fileURLToPath(import.meta.url);
|
|
|
|
|
const runner = path.resolve(filename, '../runner.js');
|
|
|
|
|
const outdir = path.resolve(filename, '../.results');
|
|
|
|
|
const report_file = `${outdir}/report.txt`;
|
|
|
|
|
|
|
|
|
|
if (fs.existsSync(outdir)) fs.rmSync(outdir, { recursive: true });
|
|
|
|
|
fs.mkdirSync(outdir);
|
|
|
|
|
|
|
|
|
|
const branches = [];
|
|
|
|
|
|
|
|
|
|
let PROFILE_DIR = path.resolve(filename, '../.profiles');
|
|
|
|
|
if (fs.existsSync(PROFILE_DIR)) fs.rmSync(PROFILE_DIR, { recursive: true });
|
|
|
|
|
fs.mkdirSync(PROFILE_DIR, { recursive: true });
|
|
|
|
|
|
|
|
|
|
for (const arg of process.argv.slice(2)) {
|
|
|
|
|
if (arg.startsWith('--')) continue;
|
|
|
|
|
if (arg === filename) continue;
|
|
|
|
|
@ -44,7 +49,12 @@ for (const branch of branches) {
|
|
|
|
|
execSync(`git checkout ${branch}`);
|
|
|
|
|
|
|
|
|
|
await new Promise((fulfil, reject) => {
|
|
|
|
|
const child = fork(runner);
|
|
|
|
|
const child = fork(runner, [], {
|
|
|
|
|
env: {
|
|
|
|
|
...process.env,
|
|
|
|
|
BENCH_PROFILE_DIR: `${PROFILE_DIR}/${safe(branch)}`
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
child.on('message', (results) => {
|
|
|
|
|
fs.writeFileSync(`${outdir}/${branch}.json`, JSON.stringify(results, null, ' '));
|
|
|
|
|
@ -57,12 +67,23 @@ for (const branch of branches) {
|
|
|
|
|
console.groupEnd();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (PROFILE_DIR !== null) {
|
|
|
|
|
console.log(`\nCPU profiles written to ${PROFILE_DIR}`);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const results = branches.map((branch) => {
|
|
|
|
|
return JSON.parse(fs.readFileSync(`${outdir}/${branch}.json`, 'utf-8'));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
fs.writeFileSync(report_file, '');
|
|
|
|
|
|
|
|
|
|
const write = (str) => {
|
|
|
|
|
fs.appendFileSync(report_file, str + '\n');
|
|
|
|
|
console.log(str);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
for (let i = 0; i < results[0].length; i += 1) {
|
|
|
|
|
console.group(`${results[0][i].benchmark}`);
|
|
|
|
|
write(`${results[0][i].benchmark}`);
|
|
|
|
|
|
|
|
|
|
for (const metric of ['time', 'gc_time']) {
|
|
|
|
|
const times = results.map((result) => +result[i][metric]);
|
|
|
|
|
@ -84,20 +105,23 @@ for (let i = 0; i < results[0].length; i += 1) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (min !== 0) {
|
|
|
|
|
console.group(`${metric}: fastest is ${char(min_index)} (${branches[min_index]})`);
|
|
|
|
|
write(` ${metric}: fastest is ${char(min_index)} (${branches[min_index]})`);
|
|
|
|
|
times.forEach((time, b) => {
|
|
|
|
|
const SIZE = 20;
|
|
|
|
|
const n = Math.round(SIZE * (time / max));
|
|
|
|
|
|
|
|
|
|
console.log(`${char(b)}: ${'◼'.repeat(n)}${' '.repeat(SIZE - n)} ${time.toFixed(2)}ms`);
|
|
|
|
|
write(` ${char(b)}: ${'◼'.repeat(n)}${' '.repeat(SIZE - n)} ${time.toFixed(2)}ms`);
|
|
|
|
|
});
|
|
|
|
|
console.groupEnd();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
console.groupEnd();
|
|
|
|
|
write('');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function char(i) {
|
|
|
|
|
return String.fromCharCode(97 + i);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function safe(name) {
|
|
|
|
|
return name.replace(/[^a-z0-9._-]+/gi, '_');
|
|
|
|
|
}
|
|
|
|
|
|