2024-06-19 21:52:20 +02:00
|
|
|
import { assert, fastest_test } from '../../utils.js';
|
|
|
|
import * as $ from '../../../packages/svelte/src/internal/client/index.js';
|
|
|
|
|
|
|
|
function setup() {
|
2024-06-20 13:34:50 +02:00
|
|
|
let head = $.source(0);
|
|
|
|
const double = $.derived(() => $.get(head) * 2);
|
|
|
|
const inverse = $.derived(() => -$.get(head));
|
|
|
|
let current = $.derived(() => {
|
|
|
|
let result = 0;
|
|
|
|
for (let i = 0; i < 20; i++) {
|
|
|
|
result += $.get(head) % 2 ? $.get(double) : $.get(inverse);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
});
|
2024-06-19 21:52:20 +02:00
|
|
|
|
|
|
|
let counter = 0;
|
|
|
|
|
|
|
|
const destroy = $.effect_root(() => {
|
|
|
|
$.render_effect(() => {
|
|
|
|
$.get(current);
|
|
|
|
counter++;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
return {
|
|
|
|
destroy,
|
|
|
|
run() {
|
|
|
|
$.flush_sync(() => {
|
|
|
|
$.set(head, 1);
|
|
|
|
});
|
|
|
|
assert($.get(current) === 40);
|
|
|
|
counter = 0;
|
|
|
|
for (let i = 0; i < 100; i++) {
|
|
|
|
$.flush_sync(() => {
|
|
|
|
$.set(head, i);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
assert(counter === 100);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2024-06-20 13:34:50 +02:00
|
|
|
export async function kairo_unstable_unowned() {
|
2024-06-19 21:52:20 +02:00
|
|
|
// 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 {
|
2024-06-20 13:34:50 +02:00
|
|
|
benchmark: 'kairo_unstable_unowned',
|
|
|
|
time: timing.time.toFixed(2),
|
|
|
|
gc_time: timing.gc_time.toFixed(2)
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function kairo_unstable_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_unstable_owned',
|
2024-06-19 21:52:20 +02:00
|
|
|
time: timing.time.toFixed(2),
|
|
|
|
gc_time: timing.gc_time.toFixed(2)
|
|
|
|
};
|
|
|
|
}
|