From cdc5356aba8ea3c51668c5215fba14e805e44016 Mon Sep 17 00:00:00 2001 From: "coderabbitai[bot]" <136622811+coderabbitai[bot]@users.noreply.github.com> Date: Sun, 13 Sep 2026 04:11:45 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=9D=20CodeRabbit=20Chat:=20Migrate=20T?= =?UTF-8?q?ypeScript=20Benchmarks=20to=20LightVM=20Bench=20API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ts/benchmarks/add_bench.ts | 31 ++++++++++++++++--------------- ts/benchmarks/assign_bench.ts | 31 ++++++++++++++++--------------- ts/benchmarks/concat_bench.ts | 31 ++++++++++++++++--------------- ts/benchmarks/dead_code_bench.ts | 31 ++++++++++++++++--------------- ts/benchmarks/io_bench.ts | 31 ++++++++++++++++--------------- 5 files changed, 80 insertions(+), 75 deletions(-) diff --git a/ts/benchmarks/add_bench.ts b/ts/benchmarks/add_bench.ts index e6865fe9..ea58e12e 100644 --- a/ts/benchmarks/add_bench.ts +++ b/ts/benchmarks/add_bench.ts @@ -8,11 +8,11 @@ * http://www.apache.org/licenses/LICENSE-2.0 */ -import { Bench } from 'tinybench'; import { LightVM, Capability } from '../../dist/index.min.mjs'; -async function runBenchmark() { - const bench = new Bench(); - const vm = new LightVM([Capability.Observe, Capability.Control]); +function runBenchmark() { + const vm = new LightVM({ + caps: [Capability.Control, Capability.Debug, Capability.Observe], + }); const raw = [ ['val', 'x'], ['push', 5], @@ -22,15 +22,16 @@ async function runBenchmark() { ]; const tools = vm.tools(); const optimized = tools.optimizeBytecode(raw); - vm.load(optimized); - bench.add('add_bench', () => { - vm.run(); - }); - await bench.run(); - bench.table().forEach((row) => { - console.log( - `Task: ${row['Task name']} | Avg Latency: ${row['Latency avg (ns)']}`, - ); - }); + + tools.bench('add_bench').run( + () => { + const benchmarkVm = new LightVM({ + caps: [Capability.Control, Capability.Debug, Capability.Observe], + }); + benchmarkVm.load(optimized); + return benchmarkVm; + }, + (benchmarkVm) => benchmarkVm.run(), + ); } -runBenchmark().catch(console.error); +runBenchmark(); diff --git a/ts/benchmarks/assign_bench.ts b/ts/benchmarks/assign_bench.ts index 7997d32a..facca0bc 100644 --- a/ts/benchmarks/assign_bench.ts +++ b/ts/benchmarks/assign_bench.ts @@ -8,11 +8,11 @@ * http://www.apache.org/licenses/LICENSE-2.0 */ -import { Bench } from 'tinybench'; import { LightVM, Capability } from '../../dist/index.min.mjs'; -async function runBenchmark() { - const bench = new Bench(); - const vm = new LightVM([Capability.Observe, Capability.Control]); +function runBenchmark() { + const vm = new LightVM({ + caps: [Capability.Control, Capability.Debug, Capability.Observe], + }); const raw = [ ['val', 'x'], ['push', 5], @@ -20,15 +20,16 @@ async function runBenchmark() { ]; const tools = vm.tools(); const optimized = tools.optimizeBytecode(raw); - vm.load(optimized); - bench.add('add_bench', () => { - vm.run(); - }); - await bench.run(); - bench.table().forEach((row) => { - console.log( - `Task: ${row['Task name']} | Avg Latency: ${row['Latency avg (ns)']}`, - ); - }); + + tools.bench('assign_bench').run( + () => { + const benchmarkVm = new LightVM({ + caps: [Capability.Control, Capability.Debug, Capability.Observe], + }); + benchmarkVm.load(optimized); + return benchmarkVm; + }, + (benchmarkVm) => benchmarkVm.run(), + ); } -runBenchmark().catch(console.error); +runBenchmark(); diff --git a/ts/benchmarks/concat_bench.ts b/ts/benchmarks/concat_bench.ts index be1a545c..0201b2df 100644 --- a/ts/benchmarks/concat_bench.ts +++ b/ts/benchmarks/concat_bench.ts @@ -8,11 +8,11 @@ * http://www.apache.org/licenses/LICENSE-2.0 */ -import { Bench } from 'tinybench'; import { LightVM, Capability } from '../../dist/index.min.mjs'; -async function runBenchmark() { - const bench = new Bench(); - const vm = new LightVM([Capability.Observe, Capability.Control]); +function runBenchmark() { + const vm = new LightVM({ + caps: [Capability.Control, Capability.Debug, Capability.Observe], + }); const raw = [ ['val', 'x'], ['push', 'Hello from '], @@ -21,15 +21,16 @@ async function runBenchmark() { ]; const tools = vm.tools(); const optimized = tools.optimizeBytecode(raw); - vm.load(optimized); - bench.add('add_bench', () => { - vm.run(); - }); - await bench.run(); - bench.table().forEach((row) => { - console.log( - `Task: ${row['Task name']} | Avg Latency: ${row['Latency avg (ns)']}`, - ); - }); + + tools.bench('concat_bench').run( + () => { + const benchmarkVm = new LightVM({ + caps: [Capability.Control, Capability.Debug, Capability.Observe], + }); + benchmarkVm.load(optimized); + return benchmarkVm; + }, + (benchmarkVm) => benchmarkVm.run(), + ); } -runBenchmark().catch(console.error); +runBenchmark(); diff --git a/ts/benchmarks/dead_code_bench.ts b/ts/benchmarks/dead_code_bench.ts index 926ac558..7fa3fe16 100644 --- a/ts/benchmarks/dead_code_bench.ts +++ b/ts/benchmarks/dead_code_bench.ts @@ -8,11 +8,11 @@ * http://www.apache.org/licenses/LICENSE-2.0 */ -import { Bench } from 'tinybench'; import { LightVM, Capability } from '../../dist/index.min.mjs'; -async function runBenchmark() { - const bench = new Bench(); - const vm = new LightVM([Capability.Observe, Capability.Control]); +function runBenchmark() { + const vm = new LightVM({ + caps: [Capability.Control, Capability.Debug, Capability.Observe], + }); const raw = [ ['push', 5], ['push', 8], @@ -20,15 +20,16 @@ async function runBenchmark() { ]; const tools = vm.tools(); const optimized = tools.optimizeBytecode(raw); - vm.load(optimized); - bench.add('add_bench', () => { - vm.run(); - }); - await bench.run(); - bench.table().forEach((row) => { - console.log( - `Task: ${row['Task name']} | Avg Latency: ${row['Latency avg (ns)']}`, - ); - }); + + tools.bench('dead_code_bench').run( + () => { + const benchmarkVm = new LightVM({ + caps: [Capability.Control, Capability.Debug, Capability.Observe], + }); + benchmarkVm.load(optimized); + return benchmarkVm; + }, + (benchmarkVm) => benchmarkVm.run(), + ); } -runBenchmark().catch(console.error); +runBenchmark(); diff --git a/ts/benchmarks/io_bench.ts b/ts/benchmarks/io_bench.ts index c2e01a37..df672c2b 100644 --- a/ts/benchmarks/io_bench.ts +++ b/ts/benchmarks/io_bench.ts @@ -8,23 +8,24 @@ * http://www.apache.org/licenses/LICENSE-2.0 */ -import { Bench } from 'tinybench'; import { LightVM, Capability } from '../../dist/index.min.mjs'; -async function runBenchmark() { - const bench = new Bench(); - const vm = new LightVM([Capability.Observe, Capability.Control]); +function runBenchmark() { + const vm = new LightVM({ + caps: [Capability.Control, Capability.Debug, Capability.Observe], + }); const raw = [['push', 'Hello from LightVM!'], ['println']]; const tools = vm.tools(); const optimized = tools.optimizeBytecode(raw); - vm.load(optimized); - bench.add('add_bench', () => { - vm.run(); - }); - await bench.run(); - bench.table().forEach((row) => { - console.log( - `Task: ${row['Task name']} | Avg Latency: ${row['Latency avg (ns)']}`, - ); - }); + + tools.bench('io_bench').run( + () => { + const benchmarkVm = new LightVM({ + caps: [Capability.Control, Capability.Debug, Capability.Observe], + }); + benchmarkVm.load(optimized); + return benchmarkVm; + }, + (benchmarkVm) => benchmarkVm.run(), + ); } -runBenchmark().catch(console.error); +runBenchmark();