Skip to content
Merged
Show file tree
Hide file tree
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
31 changes: 16 additions & 15 deletions ts/benchmarks/add_bench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand All @@ -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();
31 changes: 16 additions & 15 deletions ts/benchmarks/assign_bench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,28 @@
* 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],
['set', 'x'],
];
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();
31 changes: 16 additions & 15 deletions ts/benchmarks/concat_bench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 '],
Expand All @@ -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();
31 changes: 16 additions & 15 deletions ts/benchmarks/dead_code_bench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,28 @@
* 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],
['add', 'i16'],
];
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();
31 changes: 16 additions & 15 deletions ts/benchmarks/io_bench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Loading