Skip to content
Open
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
90 changes: 68 additions & 22 deletions src/lib/BenchmarksCharts.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

let { bench } = $props();

let Scatter = $state(null);
let Bar = $state(null);
let ready = $state(false);

let timeCmp = $state(null);
Expand All @@ -22,17 +22,17 @@

const {
Chart: ChartJS,
CategoryScale,
LinearScale,
PointElement,
LineElement,
BarElement,
Tooltip,
Legend,
Title
} = chartjs;

ChartJS.register(LinearScale, PointElement, LineElement, Tooltip, Legend, Title);
ChartJS.register(CategoryScale, LinearScale, BarElement, Tooltip, Legend, Title);

Scatter = svelteChart.Scatter;
Bar = svelteChart.Bar;
ready = true;
dpr = window.devicePixelRatio || 1;
})();
Expand Down Expand Up @@ -78,71 +78,117 @@
let algoNames = $derived.by(() => Object.keys(bench?.timeSec ?? {}).sort());

let timeData = $derived.by(() => ({
labels: inputSizes.map(x => String(x)),
datasets: algoNames.map((name, i) => ({
label: name,
data: inputSizes.map((x, j) => ({ x, y: Number(bench?.timeSec?.[name]?.[j] ?? NaN) })),
data: inputSizes.map((x, j) => Number(bench?.timeSec?.[name]?.[j] ?? NaN)),
backgroundColor: colorForIndex(i),
borderColor: colorForIndex(i),
showLine: false,
pointRadius: 3
borderColor: colorForIndex(i)
}))
}));

let memData = $derived.by(() => ({
labels: inputSizes.map(x => String(x)),
datasets: algoNames.map((name, i) => ({
label: name,
data: inputSizes.map((x, j) => ({ x, y: Number(bench?.memoryBytes?.[name]?.[j] ?? NaN) })),
data: inputSizes.map((x, j) => Number(bench?.memoryBytes?.[name]?.[j] ?? NaN)),
backgroundColor: colorForIndex(i),
borderColor: colorForIndex(i),
showLine: false,
pointRadius: 3
borderColor: colorForIndex(i)
}))
}));

let baseOptions = $derived.by(() => ({
responsive: true,
maintainAspectRatio: false,
devicePixelRatio: dpr,
plugins: { legend: { position: "bottom" } },
plugins: {
legend: {
position: "bottom",
labels: {
font: { size: 18 }
}
}
},
scales: {
x: { type: "linear", title: { display: true, text: $t("benchmarks.axes.x_input_size_chars") } }
x: {
title: {
display: true,
text: $t("benchmarks.axes.x_input_size_chars"),
font: { size: 18 }
},
ticks: {
font: { size: 16 }
}
}
}
}));

let timeOptions = $derived.by(() => ({
...baseOptions,
plugins: { ...baseOptions.plugins, title: { display: true, text: $t("benchmarks.charts.time_title") + ": " + bench.generatorName } },
plugins: {
...baseOptions.plugins,
title: {
display: true,
text: $t("benchmarks.charts.time_title") + ": " + bench.generatorName,
font: { size: 20 }
}
},
scales: {
...baseOptions.scales,
y: { title: { display: true, text: $t("benchmarks.axes.y_time_sec") } }
y: {
title: {
display: true,
text: $t("benchmarks.axes.y_time_sec"),
font: { size: 18 }
},
ticks: {
font: { size: 16 }
}
}
}
}));

let memOptions = $derived.by(() => ({
...baseOptions,
plugins: { ...baseOptions.plugins, title: { display: true, text: $t("benchmarks.charts.memory_title") + ": " + bench.generatorName } },
plugins: {
...baseOptions.plugins,
title: {
display: true,
text: $t("benchmarks.charts.memory_title") + ": " + bench.generatorName,
font: { size: 20 }
}
},
scales: {
...baseOptions.scales,
y: { title: { display: true, text: $t("benchmarks.axes.y_memory_bytes") } }
y: {
title: {
display: true,
text: $t("benchmarks.axes.y_memory_bytes"),
font: { size: 18 }
},
ticks: {
font: { size: 16 }
}
}
}
}));

let stderrText = $derived.by(() => String(bench?.stderr ?? "").trim());
</script>

{#if ready && bench && Scatter}
{#if ready && bench && Bar}
{#if stderrText !== ""}
<pre class="err">{$t("benchmarks.errors.stderr_title")}:<br><br>{stderrText}</pre>
{/if}

{#key redrawKey}
<div class="charts">
<div class="chartBox">
<Scatter bind:this={timeCmp} data={timeData} options={timeOptions} />
<Bar bind:this={timeCmp} data={timeData} options={timeOptions} />
</div>

<div class="chartBox">
<Scatter bind:this={memCmp} data={memData} options={memOptions} />
<Bar bind:this={memCmp} data={memData} options={memOptions} />
</div>
</div>
{/key}
Expand Down