Skip to content

Commit cdb35e3

Browse files
committed
benchmark: move to Bun + mitata
The React version of the benchmark has been removed, since the react-component-benchmark library is not compatible with React 19. The React-only libraries have been added to the Bunch benchmark too, using the canvas module. See benchmark/index.ts for more details on the implementation.
1 parent c46533c commit cdb35e3

File tree

7 files changed

+385
-4018
lines changed

7 files changed

+385
-4018
lines changed

benchmark/bun.lock

+312
Large diffs are not rendered by default.

benchmark/declarations.d.ts

-8
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,6 @@ declare module "@download/blockies" {
66
}): HTMLCanvasElement;
77
}
88

9-
declare module "blockies-react-svg/dist/es/BlockiesSvgSync.mjs" {
10-
export default function BlockiesSvgSync(props: {
11-
address: string;
12-
size: number;
13-
scale: number;
14-
}): JSX.Element;
15-
}
16-
179
declare module "blockies-react-svg/dist/es/makeBlockiesUrl.mjs" {
1810
export default function makeBlockiesUrl(
1911
address: string,

benchmark/index.ts

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import { bench, compact, run, summary } from "mitata";
2+
3+
import { createIcon as blockies_createIcon } from "@download/blockies";
4+
import { blo } from "blo";
5+
import blockiesReactSvg_makeBlockiesUrl from "blockies-react-svg/dist/es/makeBlockiesUrl.mjs";
6+
import { create as blockiesTs_create } from "blockies-ts";
7+
import ethereumBlockiesBase64_makeBlockie from "ethereum-blockies-base64";
8+
import ReactBlockies_Identicon from "react-blockies";
9+
import { canvasPolyfill } from "./canvas-polyfill.js";
10+
11+
canvasPolyfill(globalThis);
12+
13+
const benchmark: Record<string, (address: `0x${string}`) => string> = {
14+
"blo": blo,
15+
"@download/blockies": (address) => (
16+
blockies_createIcon({
17+
seed: address.toLowerCase(),
18+
scale: 8,
19+
size: 64,
20+
}).toDataURL()
21+
),
22+
"blockies-react-svg": (address) => (
23+
blockiesReactSvg_makeBlockiesUrl(address, 8, false, 64)
24+
),
25+
"blockies-ts": (address) => (
26+
blockiesTs_create({
27+
seed: address.toLowerCase(),
28+
size: 8,
29+
scale: 64,
30+
}).toDataURL()
31+
),
32+
"ethereum-blockies-base64": ethereumBlockiesBase64_makeBlockie,
33+
"react-blockies": (address) => {
34+
const canvas = document.createElement("canvas");
35+
const { generateIdenticon } = ReactBlockies_Identicon.prototype;
36+
generateIdenticon.call({
37+
identicon: {
38+
getContext: canvas.getContext.bind(canvas),
39+
style: {},
40+
},
41+
}, {
42+
seed: address.toLowerCase(),
43+
size: 8,
44+
scale: 64,
45+
});
46+
return canvas.toDataURL();
47+
},
48+
};
49+
50+
let currentAddress = BigInt("0x" + "1".repeat(40));
51+
function address(): `0x${string}` {
52+
return `0x${(currentAddress++).toString(16)}`;
53+
}
54+
55+
compact(() => {
56+
summary(() => {
57+
for (const [name, fn] of Object.entries(benchmark)) {
58+
bench(name, () => fn(address()));
59+
}
60+
});
61+
});
62+
63+
await run({
64+
format: "mitata",
65+
throw: true,
66+
colors: true,
67+
});

benchmark/main.bench.ts

-82
This file was deleted.

benchmark/package.json

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,20 @@
33
"private": true,
44
"type": "module",
55
"scripts": {
6-
"bench": "vitest bench"
6+
"bench": "bun index.ts"
77
},
88
"dependencies": {
99
"@download/blockies": "^1.0.3",
1010
"@types/react": "^19.0.12",
1111
"@types/react-dom": "^19.0.4",
12+
"blo": "latest",
1213
"blockies-react-svg": "^0.0.13",
1314
"blockies-ts": "^1.0.0",
1415
"canvas": "^3.1.0",
1516
"ethereum-blockies-base64": "^1.0.2",
17+
"mitata": "^1.0.34",
1618
"rand-seed": "^2.1.7",
1719
"react-blockies": "^1.4.1",
18-
"typescript": "^5.4.4",
19-
"vitest": "^3.0.9"
20+
"typescript": "^5.4.4"
2021
}
2122
}

0 commit comments

Comments
 (0)