Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/benchmark.js-plugin/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
23 changes: 16 additions & 7 deletions packages/benchmark.js-plugin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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());
Expand All @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion packages/tinybench-plugin/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@codspeed/tinybench-plugin",
"version": "1.1.0",
"version": "1.2.0",
"description": "tinybench compatibility layer for CodSpeed",
"keywords": [
"codspeed",
Expand Down
8 changes: 5 additions & 3 deletions packages/tinybench-plugin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.`);
Expand Down