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.
102 lines
1.8 KiB
102 lines
1.8 KiB
1 month ago
|
import { assert, fastest_test } from '../../../utils.js';
|
||
|
import * as $ from 'svelte/internal/client';
|
||
7 months ago
|
|
||
|
let width = 5;
|
||
|
|
||
|
function setup() {
|
||
4 months ago
|
let head = $.state(0);
|
||
6 months ago
|
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);
|
||
|
});
|
||
7 months ago
|
let counter = 0;
|
||
|
|
||
|
const destroy = $.effect_root(() => {
|
||
|
$.render_effect(() => {
|
||
|
$.get(sum);
|
||
|
counter++;
|
||
|
});
|
||
|
});
|
||
|
|
||
|
return {
|
||
|
destroy,
|
||
|
run() {
|
||
|
$.flush_sync(() => {
|
||
|
$.set(head, 1);
|
||
|
});
|
||
|
assert($.get(sum) === 2 * width);
|
||
|
counter = 0;
|
||
|
for (let i = 0; i < 500; i++) {
|
||
|
$.flush_sync(() => {
|
||
|
$.set(head, i);
|
||
|
});
|
||
|
assert($.get(sum) === (i + 1) * width);
|
||
|
}
|
||
|
assert(counter === 500);
|
||
|
}
|
||
|
};
|
||
|
}
|
||
|
|
||
6 months ago
|
export async function kairo_diamond_unowned() {
|
||
7 months ago
|
// 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 {
|
||
6 months ago
|
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',
|
||
7 months ago
|
time: timing.time.toFixed(2),
|
||
|
gc_time: timing.gc_time.toFixed(2)
|
||
|
};
|
||
|
}
|