diff --git a/packages/benchmark.js-plugin/package.json b/packages/benchmark.js-plugin/package.json index de76b329..a3226d4d 100644 --- a/packages/benchmark.js-plugin/package.json +++ b/packages/benchmark.js-plugin/package.json @@ -1,6 +1,6 @@ { "name": "@codspeed/benchmark.js-plugin", - "version": "1.1.0", + "version": "1.2.0", "description": "Benchmark.js compatibility layer for CodSpeed", "keywords": [ "codspeed", diff --git a/packages/benchmark.js-plugin/src/index.ts b/packages/benchmark.js-plugin/src/index.ts index 3abece70..0fdfbeda 100644 --- a/packages/benchmark.js-plugin/src/index.ts +++ b/packages/benchmark.js-plugin/src/index.ts @@ -8,6 +8,7 @@ import Benchmark from "benchmark"; import { findUpSync, Options as FindupOptions } from "find-up"; import path, { dirname } from "path"; import { get as getStackTrace } from "stack-trace"; +import { fileURLToPath } from "url"; declare const __VERSION__: string; @@ -177,16 +178,21 @@ async function runBenchmarks({ } else { benchPayload = bench.fn as CallableFunction; } + if (isAsync) { await optimizeFunction(benchPayload); - measurement.startInstrumentation(); - await benchPayload(); - measurement.stopInstrumentation(uri); + await (async function __codspeed_root_frame__() { + measurement.startInstrumentation(); + await benchPayload(); + measurement.stopInstrumentation(uri); + })(); } else { optimizeFunctionSync(benchPayload); - measurement.startInstrumentation(); - benchPayload(); - measurement.stopInstrumentation(uri); + (function __codspeed_root_frame__() { + measurement.startInstrumentation(); + benchPayload(); + measurement.stopInstrumentation(uri); + })(); } console.log(` ✔ Measured ${uri}`); benchmarkCompletedListeners.forEach((listener) => listener()); @@ -196,11 +202,14 @@ async function runBenchmarks({ function getCallingFile(): string { const stack = getStackTrace(); - const callingFile = stack[3].getFileName(); // [here, withCodSpeed, withCodSpeedX, actual caller] + let callingFile = stack[3].getFileName(); // [here, withCodSpeed, withCodSpeedX, actual caller] const gitDir = getGitDir(callingFile); if (gitDir === undefined) { throw new Error("Could not find a git repository"); } + if (callingFile.startsWith("file://")) { + callingFile = fileURLToPath(callingFile); + } return path.relative(gitDir, callingFile); } diff --git a/packages/core/package.json b/packages/core/package.json index 01f7f09d..57270012 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -1,6 +1,6 @@ { "name": "@codspeed/core", - "version": "1.1.0", + "version": "1.2.0", "description": "The core Node library used to integrate with Codspeed runners", "keywords": [ "codspeed", diff --git a/packages/tinybench-plugin/package.json b/packages/tinybench-plugin/package.json index 75c85a90..ac79febd 100644 --- a/packages/tinybench-plugin/package.json +++ b/packages/tinybench-plugin/package.json @@ -1,6 +1,6 @@ { "name": "@codspeed/tinybench-plugin", - "version": "1.1.0", + "version": "1.2.0", "description": "tinybench compatibility layer for CodSpeed", "keywords": [ "codspeed", diff --git a/packages/tinybench-plugin/src/index.ts b/packages/tinybench-plugin/src/index.ts index 00888f88..205c8688 100644 --- a/packages/tinybench-plugin/src/index.ts +++ b/packages/tinybench-plugin/src/index.ts @@ -25,9 +25,11 @@ export function withCodSpeed(bench: Bench): Bench { for (const task of bench.tasks) { const uri = callingFile + "::" + task.name; await optimizeFunction(task.fn); - measurement.startInstrumentation(); - await task.fn(); - measurement.stopInstrumentation(uri); + await (async function __codspeed_root_frame__() { + measurement.startInstrumentation(); + await task.fn(); + measurement.stopInstrumentation(uri); + })(); console.log(` ✔ Measured ${uri}`); } console.log(`[CodSpeed] Done running ${bench.tasks.length} benches.`);