Files
frontend/test/benchmarks/chart-helpers.bench.ts
T
841729af93 Upgrade vitest to v5 (#54011)
* Update vitest monorepo to v5

* Add required Vite peer dependency for Vitest 5

* Migrate benchmarks to the Vitest 5 context API

* Stub read-only jsdom globals in Vitest tests

* Revise benchmark reporting instructions in README

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Aidan Timson <aidan@timmo.dev>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
2026-09-08 14:29:24 +03:00

56 lines
1.9 KiB
TypeScript

import { describe, test } from "vitest";
import type { BarSeriesOption } from "echarts/types/dist/shared";
import { fillDataGapsAndRoundCaps } from "../../src/components/chart/round-caps";
import { computeYAxisFractionDigits } from "../../src/components/chart/y-axis-fraction-digits";
import { FIXED_EPOCH_MS } from "../fixtures/history-states";
import { createSeededRandom } from "../fixtures/random";
const buildBarDatasets = (
seed: number,
stacked: boolean
): BarSeriesOption[] => {
const random = createSeededRandom(seed);
const datasets: BarSeriesOption[] = [];
for (let series = 0; series < 8; series++) {
const data: [number, number][] = [];
for (let i = 0; i < 744; i++) {
if (random() < 0.2) continue; // gaps to fill
data.push([
FIXED_EPOCH_MS + i * 3_600_000,
(random() - 0.3) * 5, // mix of positive and negative bars
]);
}
datasets.push({
data,
stack: stacked ? `stack-${series % 2}` : undefined,
});
}
return datasets;
};
describe("fillDataGapsAndRoundCaps", () => {
// fillDataGapsAndRoundCaps mutates its input, so rebuild per iteration;
// build cost is included in both baseline and comparison runs.
test("stacked, 8 series, month of hourly bars", async ({ bench }) => {
await bench("stacked, 8 series, month of hourly bars", () => {
fillDataGapsAndRoundCaps(buildBarDatasets(1, true), true);
}).run();
});
test("non-stacked, 8 series, month of hourly bars", async ({ bench }) => {
await bench("non-stacked, 8 series, month of hourly bars", () => {
fillDataGapsAndRoundCaps(buildBarDatasets(2, false), false);
}).run();
});
});
describe("computeYAxisFractionDigits", () => {
test("typical ranges", async ({ bench }) => {
await bench("typical ranges", () => {
computeYAxisFractionDigits(0, 100);
computeYAxisFractionDigits(1.85, 2.0);
computeYAxisFractionDigits(0, 0.005);
}).run();
});
});