|
| 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 | +}); |
0 commit comments