aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/docs/components/pages/TRPG-home/DocsBenchmarkStat.tsx
diff options
context:
space:
mode:
author简律纯 <hsiangnianian@outlook.com>2023-05-03 01:22:45 +0800
committer简律纯 <hsiangnianian@outlook.com>2023-05-03 01:22:45 +0800
commite76a5f847e78fee4e62f6eb37d468557a1504c55 (patch)
tree4bcdeeeafb5bdc5945d855a22e6495926b5fbdd6 /docs/components/pages/TRPG-home/DocsBenchmarkStat.tsx
parent4ddbf86780b7dd2f74f8fcc037ede1222f73f81e (diff)
downloadHydroRoll-e76a5f847e78fee4e62f6eb37d468557a1504c55.tar.gz
HydroRoll-e76a5f847e78fee4e62f6eb37d468557a1504c55.zip
Diffstat (limited to 'docs/components/pages/TRPG-home/DocsBenchmarkStat.tsx')
-rw-r--r--docs/components/pages/TRPG-home/DocsBenchmarkStat.tsx53
1 files changed, 53 insertions, 0 deletions
diff --git a/docs/components/pages/TRPG-home/DocsBenchmarkStat.tsx b/docs/components/pages/TRPG-home/DocsBenchmarkStat.tsx
new file mode 100644
index 0000000..5b8dcf6
--- /dev/null
+++ b/docs/components/pages/TRPG-home/DocsBenchmarkStat.tsx
@@ -0,0 +1,53 @@
+import benchmarkData from "./benchmark-data/data.json";
+
+type StatFunc = (data: typeof benchmarkData) => string;
+
+/**
+ * Replace with satisfies keyword when TS 4.9 drops
+ */
+const satisfies =
+ <T,>() =>
+ <U extends T>(t: U) =>
+ t;
+
+const formatToSeconds = (seconds: number) => `${seconds.toFixed(1)}s`;
+const formatPercentage = (percentage: number) => `${percentage.toFixed(1)}x`;
+
+const stats = satisfies<Record<string, StatFunc>>()({
+ "next12-cold-1000": (data) => formatToSeconds(data.cold[1000].next12),
+ "turbopack-cold-1000": (data) => formatToSeconds(data.cold[1000].next13),
+ "turbopack-cold-vs-next12": (data) =>
+ formatPercentage(data.cold[1000].next12 / data.cold[1000].next13),
+ "turbopack-cold-vs-next12-30000": (data) =>
+ formatPercentage(data.cold[30000].next12 / data.cold[30000].next13),
+ "turbopack-update-vs-next12": (data) =>
+ formatPercentage(
+ data.file_change[1000].next12 / data.file_change[1000].next13
+ ),
+ "turbopack-update-vs-next12-30000": (data) =>
+ formatPercentage(
+ data.file_change[30000].next12 / data.file_change[30000].next13
+ ),
+ "vite-cold-1000": (data) => formatToSeconds(data.cold[1000].vite),
+ "turbopack-cold-vs-vite": (data) =>
+ formatPercentage(data.cold[1000].vite / data.cold[1000].next13),
+ "turbopack-cold-vs-vite-30000": (data) =>
+ formatPercentage(data.cold[30000].vite / data.cold[30000].next13),
+ "turbopack-update-vs-vite": (data) =>
+ formatPercentage(
+ data.file_change[1000].vite / data.file_change[1000].next13
+ ),
+ "turbopack-update-vs-vite-30000": (data) =>
+ formatPercentage(
+ data.file_change[30000].vite / data.file_change[30000].next13
+ ),
+});
+
+type Stat = keyof typeof stats;
+
+export function DocsBenchmarkStat(props: { stat: Stat }) {
+ if (!stats[props.stat]) {
+ throw new Error(`Invalid stat: ${props.stat}`);
+ }
+ return stats[props.stat](benchmarkData);
+}