Skip to content

Commit ba8d8ed

Browse files
benchmarks (#146)
* benchmarks * full benchmarks * don't need the title in each chart when we have the title above
1 parent a57ce05 commit ba8d8ed

File tree

8 files changed

+195
-11
lines changed

8 files changed

+195
-11
lines changed

docusaurus.config.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ const config: Config = {
5454
markdown: {
5555
mermaid: true,
5656
},
57-
themes: ['@docusaurus/theme-mermaid'],
57+
themes: ["@docusaurus/theme-mermaid"],
5858

5959
themeConfig: {
6060
// Replace with your project's social card
@@ -86,7 +86,7 @@ const config: Config = {
8686
position: "right",
8787
},
8888
{
89-
href: "https://boajs.dev/boa/dev/bench/",
89+
href: "/benchmarks",
9090
label: "Benchmarks",
9191
position: "right",
9292
},
@@ -160,7 +160,7 @@ const config: Config = {
160160
additionalLanguages: ["rust", "toml"],
161161
},
162162
mermaid: {
163-
theme: { light: 'dark', dark: 'dark' },
163+
theme: { light: "dark", dark: "dark" },
164164
},
165165
} satisfies Preset.ThemeConfig,
166166
plugins: [
@@ -211,7 +211,7 @@ const config: Config = {
211211
return undefined;
212212
},
213213
},
214-
]
214+
],
215215
],
216216
};
217217

package-lock.json

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@
2727
"lint": "prettier --check . && tsc && eslint ."
2828
},
2929
"dependencies": {
30+
"@boa-dev/boa_wasm": "^0.18.0",
3031
"@docusaurus/core": "^3.1.1",
3132
"@docusaurus/plugin-content-pages": "^3.1.1",
3233
"@docusaurus/preset-classic": "^3.1.1",
3334
"@docusaurus/theme-mermaid": "^3.1.1",
3435
"@mdx-js/react": "^3.0.1",
3536
"@monaco-editor/react": "^4.6.0",
36-
"@boa-dev/boa_wasm": "^0.18.0",
37-
"chart.js": "^4.4.1",
37+
"chart.js": "^4.4.2",
3838
"clsx": "^2.1.0",
3939
"prism-react-renderer": "^2.3.1",
4040
"react": "^18.2.0",

src/components/benchmarks/index.tsx

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
import { useColorMode } from "@docusaurus/theme-common";
2+
import Heading from "@theme/Heading";
3+
import {
4+
BarElement,
5+
CategoryScale,
6+
Chart as ChartJS,
7+
Colors,
8+
Legend,
9+
LineElement,
10+
LinearScale,
11+
PointElement,
12+
Title,
13+
Tooltip,
14+
} from "chart.js";
15+
import React from "react";
16+
import { Bar, Line } from "react-chartjs-2";
17+
import styles from "./styles.module.css";
18+
19+
ChartJS.register(
20+
CategoryScale,
21+
LinearScale,
22+
PointElement,
23+
LineElement,
24+
Title,
25+
Tooltip,
26+
Legend,
27+
Colors,
28+
BarElement
29+
);
30+
31+
export function BenchmarkGraphs() {
32+
const [data, setData] = React.useState([]);
33+
const colorMode = useColorMode();
34+
ChartJS.defaults.color = colorMode.colorMode === "light" ? "#666" : "white";
35+
36+
React.useEffect(() => {
37+
Promise.all([
38+
buildChartFromBenchmark("Crypto"),
39+
buildChartFromBenchmark("DeltaBlue"),
40+
buildChartFromBenchmark("EarleyBoyer"),
41+
buildChartFromBenchmark("NavierStokes"),
42+
buildChartFromBenchmark("RayTrace"),
43+
buildChartFromBenchmark("RegExp"),
44+
buildChartFromBenchmark("Richards"),
45+
buildChartFromBenchmark("Splay"),
46+
buildChartFromBenchmark("score"),
47+
]).then((charts) => setData(charts));
48+
}, [colorMode.colorMode]);
49+
50+
return data && data.map((chart) => chart);
51+
}
52+
53+
const buildChartFromBenchmark = async (name: string) => {
54+
const data = await fetchData(
55+
`https://raw.githubusercontent.com/boa-dev/data/main/bench/results/${name}.json`
56+
);
57+
58+
const barData = getBarChartData(data);
59+
60+
return (
61+
<div key={name}>
62+
<div className={`card__header ${styles["benchmark-card-header"]}`}>
63+
<Heading as="h2">{name}</Heading>
64+
</div>
65+
<div className={styles["cards-wrap"]}>
66+
<div className={`card ${styles["benchmark-card"]}`}>
67+
<Line data={data}></Line>
68+
</div>
69+
<div className={`card ${styles["benchmark-card"]}`}>
70+
<Bar data={barData}></Bar>
71+
</div>
72+
</div>
73+
</div>
74+
);
75+
};
76+
77+
const fetchData = async (url: string) => {
78+
const response = await fetch(url);
79+
const data = await response.json();
80+
return {
81+
labels: data.labels.map((epoch: number) =>
82+
new Date(epoch).toLocaleDateString()
83+
),
84+
datasets: [
85+
{
86+
label: "boa",
87+
data: data.results["boa"],
88+
fill: false,
89+
},
90+
{
91+
label: "v8-jitless",
92+
data: data.results["v8-jitless"],
93+
fill: false,
94+
},
95+
{
96+
label: "libjs",
97+
data: data.results["libjs"],
98+
fill: false,
99+
},
100+
{
101+
label: "duktape",
102+
data: data.results["duktape"],
103+
fill: false,
104+
},
105+
{
106+
label: "quickjs",
107+
data: data.results["quickjs"],
108+
fill: false,
109+
},
110+
],
111+
};
112+
};
113+
114+
const getBarChartData = (data) => {
115+
// We only want the last value from each dataset
116+
return {
117+
labels: [data.labels[data.labels.length - 1]],
118+
datasets: data.datasets.map((dataset) => {
119+
return {
120+
label: dataset.label,
121+
data: [dataset.data[dataset.data.length - 1]],
122+
};
123+
}),
124+
};
125+
};
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
.cards-wrap {
2+
display: flex;
3+
flex-wrap: wrap;
4+
justify-content: space-between;
5+
}
6+
7+
.benchmark-card-header {
8+
margin-bottom: 24px;
9+
}
10+
11+
.benchmark-card {
12+
margin-bottom: 24px;
13+
width: 44vw;
14+
}
15+
16+
@media screen and (max-width: 996px) {
17+
.cards-wrap {
18+
display: block;
19+
}
20+
21+
.benchmark-card {
22+
margin-bottom: 24px;
23+
width: 100%;
24+
}
25+
}

src/css/custom.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,7 @@ html[data-theme="dark"] {
5353
.footer__links {
5454
text-align: center;
5555
}
56+
57+
.navbar--fixed-top {
58+
margin-bottom: 24px;
59+
}

src/pages/benchmarks/index.tsx

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import Link from "@docusaurus/Link";
2+
import { BenchmarkGraphs } from "@site/src/components/benchmarks";
3+
import Heading from "@theme/Heading";
4+
import Layout from "@theme/Layout";
5+
import styles from "./styles.module.css";
6+
7+
export default function Benchmarks() {
8+
return (
9+
<Layout title="Benchmarks" description="Boa Benchmarks Page">
10+
<div className={styles.container}>
11+
<Heading as="h1">Benchmarks</Heading>
12+
<p>
13+
These benchmarks are taken from the{" "}
14+
<Link to="https://github.com/mozilla/arewefastyet/tree/master/benchmarks/v8-v7">
15+
V8 benchmark suite V7.{" "}
16+
</Link>
17+
Our <Link to="https://github.com/boa-dev/data">data repo</Link> runs
18+
these benchmarks against the listed engines every night using Github
19+
actions.
20+
</p>
21+
<p>The higher the score the better.</p>
22+
<BenchmarkGraphs />
23+
</div>
24+
</Layout>
25+
);
26+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.container {
2+
width: 90vw;
3+
align-self: center;
4+
}

0 commit comments

Comments
 (0)