From 73d7ef6ee622870b2dcf5a3144dbe961f4768835 Mon Sep 17 00:00:00 2001 From: alvrs Date: Tue, 5 Dec 2023 19:21:26 +0100 Subject: [PATCH] feat(common): add simple util to log benchmarks --- packages/common/src/createBenchmark.ts | 12 ++++++++++++ packages/common/src/index.ts | 1 + 2 files changed, 13 insertions(+) create mode 100644 packages/common/src/createBenchmark.ts 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";