From 198692ebacf092bc25284d5988fb8bcd3acef62b Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Wed, 19 Jun 2024 16:08:27 -0400 Subject: [PATCH] WIP compare script --- benchmarking/benchmarks.js | 24 ++++++++++++++++ benchmarking/compare.js | 58 ++++++++++++++++++++++++++++++++++++++ benchmarking/run.js | 57 ++++++++++--------------------------- 3 files changed, 97 insertions(+), 42 deletions(-) create mode 100644 benchmarking/benchmarks.js create mode 100644 benchmarking/compare.js diff --git a/benchmarking/benchmarks.js b/benchmarking/benchmarks.js new file mode 100644 index 0000000000..283112dbe3 --- /dev/null +++ b/benchmarking/benchmarks.js @@ -0,0 +1,24 @@ +import { kairo_avoidable } from './benchmarks/kairo/kairo_avoidable.js'; +import { kairo_broad } from './benchmarks/kairo/kairo_broad.js'; +import { kairo_deep } from './benchmarks/kairo/kairo_deep.js'; +import { kairo_diamond } from './benchmarks/kairo/kairo_diamond.js'; +import { kairo_mux } from './benchmarks/kairo/kairo_mux.js'; +import { kairo_repeated } from './benchmarks/kairo/kairo_repeated.js'; +import { kairo_triangle } from './benchmarks/kairo/kairo_triangle.js'; +import { kairo_unstable } from './benchmarks/kairo/kairo_unstable.js'; +import { mol_bench } from './benchmarks/mol_bench.js'; + +// This benchmark has been adapted from the js-reactivity-benchmark (https://github.com/milomg/js-reactivity-benchmark) +// Not all tests are the same, and many parts have been tweaked to capture different data. + +export const benchmarks = [ + kairo_avoidable, + kairo_broad, + kairo_deep, + kairo_diamond, + kairo_triangle, + kairo_mux, + kairo_repeated, + kairo_unstable, + mol_bench +]; diff --git a/benchmarking/compare.js b/benchmarking/compare.js new file mode 100644 index 0000000000..4d522292d5 --- /dev/null +++ b/benchmarking/compare.js @@ -0,0 +1,58 @@ +import fs from 'node:fs'; +import { execSync } from 'node:child_process'; +import { fileURLToPath } from 'node:url'; +import { benchmarks } from './benchmarks.js'; + +const results = fileURLToPath(new URL('./.results', import.meta.url)); + +console.log(results); + +const [ + a = execSync('git symbolic-ref --short -q HEAD || git rev-parse --short HEAD').toString().trim(), + b = 'main' +] = process.argv.slice(2); + +const a_hash = execSync(`git rev-parse ${a}`).toString().trim(); +const b_hash = execSync(`git rev-parse ${b}`).toString().trim(); + +if (a_hash === b_hash) { + console.log('Branches are the same'); + process.exit(0); +} + +/** @type {TODO[]} */ +let a_results; + +/** @type {TODO[]} */ +let b_results; + +async function run() { + const results = []; + for (const benchmark of benchmarks) { + const result = await benchmark(); + console.log(result.name); + results.push(result); + } + return results; +} + +// step 1 — run the benchmark on the current branch +{ + a_results = await run(); + console.log(a_results); + + fs.writeFileSync(`${results}/${a_hash.slice(0, 8)}.json`, JSON.stringify(a_results, null, ' ')); +} + +// step 2 — run the benchmark on the comparison branch (usually main) +{ + b_results = await run(); + console.log(b_results); + + fs.writeFileSync(`${results}/${b_hash.slice(0, 8)}.json`, JSON.stringify(b_results, null, ' ')); +} + +// step 3 — compare the results +{ + // TODO +} diff --git a/benchmarking/run.js b/benchmarking/run.js index 8114641be6..0d774b234c 100644 --- a/benchmarking/run.js +++ b/benchmarking/run.js @@ -1,48 +1,21 @@ import * as $ from '../packages/svelte/src/internal/client/index.js'; -import { kairo_avoidable } from './benchmarks/kairo/kairo_avoidable.js'; -import { kairo_broad } from './benchmarks/kairo/kairo_broad.js'; -import { kairo_deep } from './benchmarks/kairo/kairo_deep.js'; -import { kairo_diamond } from './benchmarks/kairo/kairo_diamond.js'; -import { kairo_mux } from './benchmarks/kairo/kairo_mux.js'; -import { kairo_repeated } from './benchmarks/kairo/kairo_repeated.js'; -import { kairo_triangle } from './benchmarks/kairo/kairo_triangle.js'; -import { kairo_unstable } from './benchmarks/kairo/kairo_unstable.js'; -import { mol_bench } from './benchmarks/mol_bench.js'; +import { benchmarks } from './benchmarks.js'; -// This benchmark has been adapted from the js-reactivity-benchmark (https://github.com/milomg/js-reactivity-benchmark) -// Not all tests are the same, and many parts have been tweaked to capture different data. - -const benchmarks = [ - kairo_avoidable, - kairo_broad, - kairo_deep, - kairo_diamond, - kairo_triangle, - kairo_mux, - kairo_repeated, - kairo_unstable, - mol_bench -]; - -async function run_benchmarks() { - // eslint-disable-next-line no-console - console.log('-- Benchmarking Started --'); - $.push({}, true); - try { - for (const benchmark of benchmarks) { - // eslint-disable-next-line no-console - console.log(await benchmark()); - } - } catch (e) { +// eslint-disable-next-line no-console +console.log('-- Benchmarking Started --'); +$.push({}, true); +try { + for (const benchmark of benchmarks) { // eslint-disable-next-line no-console - console.error('-- Benchmarking Failed --'); - // eslint-disable-next-line no-console - console.error(e); - process.exit(1); + console.log(await benchmark()); } - $.pop(); +} catch (e) { + // eslint-disable-next-line no-console + console.error('-- Benchmarking Failed --'); // eslint-disable-next-line no-console - console.log('-- Benchmarking Complete --'); + console.error(e); + process.exit(1); } - -run_benchmarks(); +$.pop(); +// eslint-disable-next-line no-console +console.log('-- Benchmarking Complete --');