diff --git a/packages/common/src/createBenchmark.ts b/packages/common/src/createBenchmark.ts new file mode 100644 index 00000000000..d6ba3d91013 --- /dev/null +++ b/packages/common/src/createBenchmark.ts @@ -0,0 +1,12 @@ +import createDebug from "debug"; + +export function createBenchmark(namespace: string): (stepName: string) => void { + const debug = createDebug("mud:benchmark" + namespace); + let lastStep = performance.now(); + + return (stepName: string) => { + const secondsSinceLastStep = (performance.now() - lastStep) / 1000; + debug("%s: +%ds", stepName, secondsSinceLastStep); + lastStep = performance.now(); + }; +} diff --git a/packages/common/src/index.ts b/packages/common/src/index.ts index 9a68f8eb5bc..c5a2061a444 100644 --- a/packages/common/src/index.ts +++ b/packages/common/src/index.ts @@ -1,4 +1,5 @@ export * from "./common"; +export * from "./createBenchmark"; export * from "./createBurnerAccount"; export * from "./createNonceManager"; export * from "./getContract";