diff --git a/src/events.ts b/src/events.ts index 3d8bee4..8266625 100644 --- a/src/events.ts +++ b/src/events.ts @@ -27,7 +27,7 @@ export const $benchmarkAfterAll = eve<{ }>(); // Before each benchmark of one type gets run -export const $benchmarkBeforeEach = eve(); +export const $benchmarkBeforeEach = eve<{ benchmark: Name }>(); // After each benchmark of one type gets run -export const $benchmarkAfterEach = eve(); +export const $benchmarkAfterEach = eve<{ benchmark: Name }>(); diff --git a/src/preset.ts b/src/preset.ts index dac1eb7..4611b58 100644 --- a/src/preset.ts +++ b/src/preset.ts @@ -47,8 +47,8 @@ export function preset(partialOptions?: DeepPartial) { await pub($benchmarkAfterAll, { suite, benchmark, - cpu: await stats(fn, "cpu", offsets), - ram: await stats(fn, "ram", offsets), + cpu: await stats(benchmark, fn, "cpu", offsets), + ram: await stats(benchmark, fn, "ram", offsets), }); } diff --git a/src/run.ts b/src/run.ts index d6d0a8e..d6dd26d 100644 --- a/src/run.ts +++ b/src/run.ts @@ -1,13 +1,13 @@ -import {pub} from "ueve/async"; +import { pub } from "ueve/async"; import { GLOBAL } from "./constants"; -import {$benchmarkAfterEach, $benchmarkBeforeEach} from "./events"; +import { $benchmarkAfterEach, $benchmarkBeforeEach, Name } from "./events"; import { RunData } from "./types"; -export async function run({ benchmark, mode, type }: RunData) { +export async function run(name: Name, { benchmark, mode, type }: RunData) { const isAsync = type === "async"; const store = GLOBAL.stores[mode].chunk; - pub($benchmarkBeforeEach, null); + await pub($benchmarkBeforeEach, { benchmark: name }); if (mode === "cpu") { const start = process.hrtime.bigint(); @@ -29,5 +29,5 @@ export async function run({ benchmark, mode, type }: RunData) { store.array[++store.index] = Math.round(Number(end - start)); } - pub($benchmarkAfterEach, null); + await pub($benchmarkAfterEach, { benchmark: name }); } diff --git a/src/stats.ts b/src/stats.ts index 34e4538..3bcabe1 100644 --- a/src/stats.ts +++ b/src/stats.ts @@ -2,8 +2,10 @@ import { GLOBAL } from "./constants"; import { getMedian, getMinMax, positive } from "./utils"; import { run } from "./run"; import { Benchmark, Mode, Offsets } from "./types"; +import { Name } from "./events"; export async function stats( + name: Name, benchmark: Benchmark, mode: Mode, offsets: Offsets, @@ -37,7 +39,7 @@ export async function stats( main.index = 0; } - await run({ benchmark, mode, type }); + await run(name, { benchmark, mode, type }); } const { array, index } = main;