Skip to content

chore: add more benchmarks #12108

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 2 commits into from
Jun 20, 2024
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
70 changes: 52 additions & 18 deletions benchmarking/benchmarks.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,58 @@
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 {
kairo_avoidable_owned,
kairo_avoidable_unowned
} from './benchmarks/kairo/kairo_avoidable.js';
import { kairo_broad_owned, kairo_broad_unowned } from './benchmarks/kairo/kairo_broad.js';
import { kairo_deep_owned, kairo_deep_unowned } from './benchmarks/kairo/kairo_deep.js';
import { kairo_diamond_owned, kairo_diamond_unowned } from './benchmarks/kairo/kairo_diamond.js';
import { kairo_mux_unowned, kairo_mux_owned } from './benchmarks/kairo/kairo_mux.js';
import { kairo_repeated_unowned, kairo_repeated_owned } from './benchmarks/kairo/kairo_repeated.js';
import { kairo_triangle_owned, kairo_triangle_unowned } from './benchmarks/kairo/kairo_triangle.js';
import { kairo_unstable_owned, kairo_unstable_unowned } from './benchmarks/kairo/kairo_unstable.js';
import { mol_bench_owned, mol_bench_unowned } from './benchmarks/mol_bench.js';
import {
sbench_create_0to1,
sbench_create_1000to1,
sbench_create_1to1,
sbench_create_1to1000,
sbench_create_1to2,
sbench_create_1to4,
sbench_create_1to8,
sbench_create_2to1,
sbench_create_4to1,
sbench_create_signals
} from './benchmarks/sbench.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
sbench_create_signals,
sbench_create_0to1,
sbench_create_1to1,
sbench_create_2to1,
sbench_create_4to1,
sbench_create_1000to1,
sbench_create_1to2,
sbench_create_1to4,
sbench_create_1to8,
sbench_create_1to1000,
kairo_avoidable_owned,
kairo_avoidable_unowned,
kairo_broad_owned,
kairo_broad_unowned,
kairo_deep_owned,
kairo_deep_unowned,
kairo_diamond_owned,
kairo_diamond_unowned,
kairo_triangle_owned,
kairo_triangle_unowned,
kairo_mux_owned,
kairo_mux_unowned,
kairo_repeated_owned,
kairo_repeated_unowned,
kairo_unstable_owned,
kairo_unstable_unowned,
mol_bench_owned,
mol_bench_unowned
];
35 changes: 33 additions & 2 deletions benchmarking/benchmarks/kairo/kairo_avoidable.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function setup() {
};
}

export async function kairo_avoidable() {
export async function kairo_avoidable_unowned() {
// Do 10 loops to warm up JIT
for (let i = 0; i < 10; i++) {
const { run, destroy } = setup();
Expand All @@ -53,7 +53,38 @@ export async function kairo_avoidable() {
destroy();

return {
benchmark: 'kairo_avoidable',
benchmark: 'kairo_avoidable_unowned',
time: timing.time.toFixed(2),
gc_time: timing.gc_time.toFixed(2)
};
}

export async function kairo_avoidable_owned() {
let run, destroy;

const destroy_owned = $.effect_root(() => {
// Do 10 loops to warm up JIT
for (let i = 0; i < 10; i++) {
const { run, destroy } = setup();
run();
destroy();
}

({ run, destroy } = setup());
});

const { timing } = await fastest_test(10, () => {
for (let i = 0; i < 100; i++) {
run();
}
});

// @ts-ignore
destroy();
destroy_owned();

return {
benchmark: 'kairo_avoidable_owned',
time: timing.time.toFixed(2),
gc_time: timing.gc_time.toFixed(2)
};
Expand Down
37 changes: 34 additions & 3 deletions benchmarking/benchmarks/kairo/kairo_broad.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function setup() {
$.flush_sync(() => {
$.set(head, 1);
});
counter = 0
counter = 0;
for (let i = 0; i < 50; i++) {
$.flush_sync(() => {
$.set(head, i);
Expand All @@ -40,7 +40,7 @@ function setup() {
};
}

export async function kairo_broad() {
export async function kairo_broad_unowned() {
// Do 10 loops to warm up JIT
for (let i = 0; i < 10; i++) {
const { run, destroy } = setup();
Expand All @@ -59,7 +59,38 @@ export async function kairo_broad() {
destroy();

return {
benchmark: 'kairo_broad',
benchmark: 'kairo_broad_unowned',
time: timing.time.toFixed(2),
gc_time: timing.gc_time.toFixed(2)
};
}

export async function kairo_broad_owned() {
let run, destroy;

const destroy_owned = $.effect_root(() => {
// Do 10 loops to warm up JIT
for (let i = 0; i < 10; i++) {
const { run, destroy } = setup();
run();
destroy();
}

({ run, destroy } = setup());
});

const { timing } = await fastest_test(10, () => {
for (let i = 0; i < 100; i++) {
run();
}
});

// @ts-ignore
destroy();
destroy_owned();

return {
benchmark: 'kairo_broad_owned',
time: timing.time.toFixed(2),
gc_time: timing.gc_time.toFixed(2)
};
Expand Down
49 changes: 40 additions & 9 deletions benchmarking/benchmarks/kairo/kairo_deep.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ function setup() {
let head = $.source(0);
let current = head;
for (let i = 0; i < len; i++) {
let c = current;
current = $.derived(() => {
return $.get(c) + 1;
});
}
let counter = 0;
let c = current;
current = $.derived(() => {
return $.get(c) + 1;
});
}
let counter = 0;

const destroy = $.effect_root(() => {
$.render_effect(() => {
Expand All @@ -28,7 +28,7 @@ function setup() {
$.flush_sync(() => {
$.set(head, 1);
});
counter = 0
counter = 0;
for (let i = 0; i < iter; i++) {
$.flush_sync(() => {
$.set(head, i);
Expand All @@ -40,7 +40,7 @@ function setup() {
};
}

export async function kairo_deep() {
export async function kairo_deep_unowned() {
// Do 10 loops to warm up JIT
for (let i = 0; i < 10; i++) {
const { run, destroy } = setup();
Expand All @@ -59,7 +59,38 @@ export async function kairo_deep() {
destroy();

return {
benchmark: 'kairo_deep',
benchmark: 'kairo_deep_unowned',
time: timing.time.toFixed(2),
gc_time: timing.gc_time.toFixed(2)
};
}

export async function kairo_deep_owned() {
let run, destroy;

const destroy_owned = $.effect_root(() => {
// Do 10 loops to warm up JIT
for (let i = 0; i < 10; i++) {
const { run, destroy } = setup();
run();
destroy();
}

({ run, destroy } = setup());
});

const { timing } = await fastest_test(10, () => {
for (let i = 0; i < 100; i++) {
run();
}
});

// @ts-ignore
destroy();
destroy_owned();

return {
benchmark: 'kairo_deep_owned',
time: timing.time.toFixed(2),
gc_time: timing.gc_time.toFixed(2)
};
Expand Down
57 changes: 44 additions & 13 deletions benchmarking/benchmarks/kairo/kairo_diamond.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ let width = 5;

function setup() {
let head = $.source(0);
let current = [];
for (let i = 0; i < width; i++) {
current.push(
$.derived(() => {
return $.get(head) + 1;
})
);
}
let sum = $.derived(() => {
return current.map((x) => $.get(x)).reduce((a, b) => a + b, 0);
});
let current = [];
for (let i = 0; i < width; i++) {
current.push(
$.derived(() => {
return $.get(head) + 1;
})
);
}
let sum = $.derived(() => {
return current.map((x) => $.get(x)).reduce((a, b) => a + b, 0);
});
let counter = 0;

const destroy = $.effect_root(() => {
Expand Down Expand Up @@ -44,7 +44,7 @@ function setup() {
};
}

export async function kairo_diamond() {
export async function kairo_diamond_unowned() {
// Do 10 loops to warm up JIT
for (let i = 0; i < 10; i++) {
const { run, destroy } = setup();
Expand All @@ -63,7 +63,38 @@ export async function kairo_diamond() {
destroy();

return {
benchmark: 'kairo_diamond',
benchmark: 'kairo_diamond_unowned',
time: timing.time.toFixed(2),
gc_time: timing.gc_time.toFixed(2)
};
}

export async function kairo_diamond_owned() {
let run, destroy;

const destroy_owned = $.effect_root(() => {
// Do 10 loops to warm up JIT
for (let i = 0; i < 10; i++) {
const { run, destroy } = setup();
run();
destroy();
}

({ run, destroy } = setup());
});

const { timing } = await fastest_test(10, () => {
for (let i = 0; i < 100; i++) {
run();
}
});

// @ts-ignore
destroy();
destroy_owned();

return {
benchmark: 'kairo_diamond_owned',
time: timing.time.toFixed(2),
gc_time: timing.gc_time.toFixed(2)
};
Expand Down
Loading
Loading