Skip to content

Commit e9e7d8b

Browse files
authored
chore: add more benchmarks (#12108)
* chore: add more benchmarks * address feedback
1 parent eca1b7f commit e9e7d8b

File tree

11 files changed

+747
-95
lines changed

11 files changed

+747
-95
lines changed

benchmarking/benchmarks.js

Lines changed: 52 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,58 @@
1-
import { kairo_avoidable } from './benchmarks/kairo/kairo_avoidable.js';
2-
import { kairo_broad } from './benchmarks/kairo/kairo_broad.js';
3-
import { kairo_deep } from './benchmarks/kairo/kairo_deep.js';
4-
import { kairo_diamond } from './benchmarks/kairo/kairo_diamond.js';
5-
import { kairo_mux } from './benchmarks/kairo/kairo_mux.js';
6-
import { kairo_repeated } from './benchmarks/kairo/kairo_repeated.js';
7-
import { kairo_triangle } from './benchmarks/kairo/kairo_triangle.js';
8-
import { kairo_unstable } from './benchmarks/kairo/kairo_unstable.js';
9-
import { mol_bench } from './benchmarks/mol_bench.js';
1+
import {
2+
kairo_avoidable_owned,
3+
kairo_avoidable_unowned
4+
} from './benchmarks/kairo/kairo_avoidable.js';
5+
import { kairo_broad_owned, kairo_broad_unowned } from './benchmarks/kairo/kairo_broad.js';
6+
import { kairo_deep_owned, kairo_deep_unowned } from './benchmarks/kairo/kairo_deep.js';
7+
import { kairo_diamond_owned, kairo_diamond_unowned } from './benchmarks/kairo/kairo_diamond.js';
8+
import { kairo_mux_unowned, kairo_mux_owned } from './benchmarks/kairo/kairo_mux.js';
9+
import { kairo_repeated_unowned, kairo_repeated_owned } from './benchmarks/kairo/kairo_repeated.js';
10+
import { kairo_triangle_owned, kairo_triangle_unowned } from './benchmarks/kairo/kairo_triangle.js';
11+
import { kairo_unstable_owned, kairo_unstable_unowned } from './benchmarks/kairo/kairo_unstable.js';
12+
import { mol_bench_owned, mol_bench_unowned } from './benchmarks/mol_bench.js';
13+
import {
14+
sbench_create_0to1,
15+
sbench_create_1000to1,
16+
sbench_create_1to1,
17+
sbench_create_1to1000,
18+
sbench_create_1to2,
19+
sbench_create_1to4,
20+
sbench_create_1to8,
21+
sbench_create_2to1,
22+
sbench_create_4to1,
23+
sbench_create_signals
24+
} from './benchmarks/sbench.js';
1025

1126
// This benchmark has been adapted from the js-reactivity-benchmark (https://github.com/milomg/js-reactivity-benchmark)
1227
// Not all tests are the same, and many parts have been tweaked to capture different data.
1328

1429
export const benchmarks = [
15-
kairo_avoidable,
16-
kairo_broad,
17-
kairo_deep,
18-
kairo_diamond,
19-
kairo_triangle,
20-
kairo_mux,
21-
kairo_repeated,
22-
kairo_unstable,
23-
mol_bench
30+
sbench_create_signals,
31+
sbench_create_0to1,
32+
sbench_create_1to1,
33+
sbench_create_2to1,
34+
sbench_create_4to1,
35+
sbench_create_1000to1,
36+
sbench_create_1to2,
37+
sbench_create_1to4,
38+
sbench_create_1to8,
39+
sbench_create_1to1000,
40+
kairo_avoidable_owned,
41+
kairo_avoidable_unowned,
42+
kairo_broad_owned,
43+
kairo_broad_unowned,
44+
kairo_deep_owned,
45+
kairo_deep_unowned,
46+
kairo_diamond_owned,
47+
kairo_diamond_unowned,
48+
kairo_triangle_owned,
49+
kairo_triangle_unowned,
50+
kairo_mux_owned,
51+
kairo_mux_unowned,
52+
kairo_repeated_owned,
53+
kairo_repeated_unowned,
54+
kairo_unstable_owned,
55+
kairo_unstable_unowned,
56+
mol_bench_owned,
57+
mol_bench_unowned
2458
];

benchmarking/benchmarks/kairo/kairo_avoidable.js

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ function setup() {
3434
};
3535
}
3636

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

5555
return {
56-
benchmark: 'kairo_avoidable',
56+
benchmark: 'kairo_avoidable_unowned',
57+
time: timing.time.toFixed(2),
58+
gc_time: timing.gc_time.toFixed(2)
59+
};
60+
}
61+
62+
export async function kairo_avoidable_owned() {
63+
let run, destroy;
64+
65+
const destroy_owned = $.effect_root(() => {
66+
// Do 10 loops to warm up JIT
67+
for (let i = 0; i < 10; i++) {
68+
const { run, destroy } = setup();
69+
run();
70+
destroy();
71+
}
72+
73+
({ run, destroy } = setup());
74+
});
75+
76+
const { timing } = await fastest_test(10, () => {
77+
for (let i = 0; i < 100; i++) {
78+
run();
79+
}
80+
});
81+
82+
// @ts-ignore
83+
destroy();
84+
destroy_owned();
85+
86+
return {
87+
benchmark: 'kairo_avoidable_owned',
5788
time: timing.time.toFixed(2),
5889
gc_time: timing.gc_time.toFixed(2)
5990
};

benchmarking/benchmarks/kairo/kairo_broad.js

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ function setup() {
2828
$.flush_sync(() => {
2929
$.set(head, 1);
3030
});
31-
counter = 0
31+
counter = 0;
3232
for (let i = 0; i < 50; i++) {
3333
$.flush_sync(() => {
3434
$.set(head, i);
@@ -40,7 +40,7 @@ function setup() {
4040
};
4141
}
4242

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

6161
return {
62-
benchmark: 'kairo_broad',
62+
benchmark: 'kairo_broad_unowned',
63+
time: timing.time.toFixed(2),
64+
gc_time: timing.gc_time.toFixed(2)
65+
};
66+
}
67+
68+
export async function kairo_broad_owned() {
69+
let run, destroy;
70+
71+
const destroy_owned = $.effect_root(() => {
72+
// Do 10 loops to warm up JIT
73+
for (let i = 0; i < 10; i++) {
74+
const { run, destroy } = setup();
75+
run();
76+
destroy();
77+
}
78+
79+
({ run, destroy } = setup());
80+
});
81+
82+
const { timing } = await fastest_test(10, () => {
83+
for (let i = 0; i < 100; i++) {
84+
run();
85+
}
86+
});
87+
88+
// @ts-ignore
89+
destroy();
90+
destroy_owned();
91+
92+
return {
93+
benchmark: 'kairo_broad_owned',
6394
time: timing.time.toFixed(2),
6495
gc_time: timing.gc_time.toFixed(2)
6596
};

benchmarking/benchmarks/kairo/kairo_deep.js

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ function setup() {
88
let head = $.source(0);
99
let current = head;
1010
for (let i = 0; i < len; i++) {
11-
let c = current;
12-
current = $.derived(() => {
13-
return $.get(c) + 1;
14-
});
15-
}
16-
let counter = 0;
11+
let c = current;
12+
current = $.derived(() => {
13+
return $.get(c) + 1;
14+
});
15+
}
16+
let counter = 0;
1717

1818
const destroy = $.effect_root(() => {
1919
$.render_effect(() => {
@@ -28,7 +28,7 @@ function setup() {
2828
$.flush_sync(() => {
2929
$.set(head, 1);
3030
});
31-
counter = 0
31+
counter = 0;
3232
for (let i = 0; i < iter; i++) {
3333
$.flush_sync(() => {
3434
$.set(head, i);
@@ -40,7 +40,7 @@ function setup() {
4040
};
4141
}
4242

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

6161
return {
62-
benchmark: 'kairo_deep',
62+
benchmark: 'kairo_deep_unowned',
63+
time: timing.time.toFixed(2),
64+
gc_time: timing.gc_time.toFixed(2)
65+
};
66+
}
67+
68+
export async function kairo_deep_owned() {
69+
let run, destroy;
70+
71+
const destroy_owned = $.effect_root(() => {
72+
// Do 10 loops to warm up JIT
73+
for (let i = 0; i < 10; i++) {
74+
const { run, destroy } = setup();
75+
run();
76+
destroy();
77+
}
78+
79+
({ run, destroy } = setup());
80+
});
81+
82+
const { timing } = await fastest_test(10, () => {
83+
for (let i = 0; i < 100; i++) {
84+
run();
85+
}
86+
});
87+
88+
// @ts-ignore
89+
destroy();
90+
destroy_owned();
91+
92+
return {
93+
benchmark: 'kairo_deep_owned',
6394
time: timing.time.toFixed(2),
6495
gc_time: timing.gc_time.toFixed(2)
6596
};

benchmarking/benchmarks/kairo/kairo_diamond.js

Lines changed: 44 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@ let width = 5;
55

66
function setup() {
77
let head = $.source(0);
8-
let current = [];
9-
for (let i = 0; i < width; i++) {
10-
current.push(
11-
$.derived(() => {
12-
return $.get(head) + 1;
13-
})
14-
);
15-
}
16-
let sum = $.derived(() => {
17-
return current.map((x) => $.get(x)).reduce((a, b) => a + b, 0);
18-
});
8+
let current = [];
9+
for (let i = 0; i < width; i++) {
10+
current.push(
11+
$.derived(() => {
12+
return $.get(head) + 1;
13+
})
14+
);
15+
}
16+
let sum = $.derived(() => {
17+
return current.map((x) => $.get(x)).reduce((a, b) => a + b, 0);
18+
});
1919
let counter = 0;
2020

2121
const destroy = $.effect_root(() => {
@@ -44,7 +44,7 @@ function setup() {
4444
};
4545
}
4646

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

6565
return {
66-
benchmark: 'kairo_diamond',
66+
benchmark: 'kairo_diamond_unowned',
67+
time: timing.time.toFixed(2),
68+
gc_time: timing.gc_time.toFixed(2)
69+
};
70+
}
71+
72+
export async function kairo_diamond_owned() {
73+
let run, destroy;
74+
75+
const destroy_owned = $.effect_root(() => {
76+
// Do 10 loops to warm up JIT
77+
for (let i = 0; i < 10; i++) {
78+
const { run, destroy } = setup();
79+
run();
80+
destroy();
81+
}
82+
83+
({ run, destroy } = setup());
84+
});
85+
86+
const { timing } = await fastest_test(10, () => {
87+
for (let i = 0; i < 100; i++) {
88+
run();
89+
}
90+
});
91+
92+
// @ts-ignore
93+
destroy();
94+
destroy_owned();
95+
96+
return {
97+
benchmark: 'kairo_diamond_owned',
6798
time: timing.time.toFixed(2),
6899
gc_time: timing.gc_time.toFixed(2)
69100
};

0 commit comments

Comments
 (0)