mirror of https://github.com/sveltejs/svelte
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
64 lines
1.3 KiB
64 lines
1.3 KiB
3 months ago
|
import { assert, fastest_test } from '../../utils.js';
|
||
|
import * as $ from '../../../packages/svelte/src/internal/client/index.js';
|
||
|
|
||
|
function setup() {
|
||
|
let heads = new Array(100).fill(null).map((_) => $.source(0));
|
||
|
const mux = $.derived(() => {
|
||
|
return Object.fromEntries(heads.map((h) => $.get(h)).entries());
|
||
|
});
|
||
|
const splited = heads
|
||
|
.map((_, index) => $.derived(() => $.get(mux)[index]))
|
||
|
.map((x) => $.derived(() => $.get(x) + 1));
|
||
|
|
||
|
const destroy = $.effect_root(() => {
|
||
|
splited.forEach((x) => {
|
||
|
$.render_effect(() => {
|
||
|
$.get(x);
|
||
|
});
|
||
|
});
|
||
|
});
|
||
|
|
||
|
return {
|
||
|
destroy,
|
||
|
run() {
|
||
|
for (let i = 0; i < 10; i++) {
|
||
|
$.flush_sync(() => {
|
||
|
$.set(heads[i], i);
|
||
|
});
|
||
|
assert($.get(splited[i]) === i + 1);
|
||
|
}
|
||
|
for (let i = 0; i < 10; i++) {
|
||
|
$.flush_sync(() => {
|
||
|
$.set(heads[i], i * 2);
|
||
|
});
|
||
|
assert($.get(splited[i]) === i * 2 + 1);
|
||
|
}
|
||
|
}
|
||
|
};
|
||
|
}
|
||
|
|
||
|
export async function kairo_mux() {
|
||
|
// Do 10 loops to warm up JIT
|
||
|
for (let i = 0; i < 10; i++) {
|
||
|
const { run, destroy } = setup();
|
||
|
run();
|
||
|
destroy();
|
||
|
}
|
||
|
|
||
|
const { run, destroy } = setup();
|
||
|
|
||
|
const { timing } = await fastest_test(10, () => {
|
||
|
for (let i = 0; i < 100; i++) {
|
||
|
run();
|
||
|
}
|
||
|
});
|
||
|
|
||
|
destroy();
|
||
|
|
||
|
return {
|
||
|
benchmark: 'kairo_mux',
|
||
|
time: timing.time.toFixed(2),
|
||
|
gc_time: timing.gc_time.toFixed(2)
|
||
|
};
|
||
|
}
|