Skip to content

Commit

Permalink
fixup! feat: add a root frame for the callgraph generation
Browse files Browse the repository at this point in the history
  • Loading branch information
art049 committed Jun 26, 2023
1 parent 91ce259 commit b226f14
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions packages/benchmark.js-plugin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,35 +164,31 @@ async function runBenchmarks({
const bench = benches[i];
const uri = baseUri + "::" + (bench.name ?? `unknown_${i}`);
const isAsync = bench.options.async || bench.options.defer;
let benchPayload;
let __codspeed_root_frame__;
if (bench.options.defer) {
benchPayload = () => {
__codspeed_root_frame__ = () => {
return new Promise((resolve, reject) => {
(bench.fn as CallableFunction)({ resolve, reject });
});
};
} else if (bench.options.async) {
benchPayload = async () => {
__codspeed_root_frame__ = async () => {
await (bench.fn as CallableFunction)();
};
} else {
benchPayload = bench.fn as CallableFunction;
__codspeed_root_frame__ = bench.fn as CallableFunction;
}

if (isAsync) {
await optimizeFunction(benchPayload);
await (async function __codspeed_root_frame__() {
measurement.startInstrumentation();
await benchPayload();
measurement.stopInstrumentation(uri);
})();
await optimizeFunction(__codspeed_root_frame__);
measurement.startInstrumentation();
await __codspeed_root_frame__();
measurement.stopInstrumentation(uri);
} else {
optimizeFunctionSync(benchPayload);
(function __codspeed_root_frame__() {
measurement.startInstrumentation();
benchPayload();
measurement.stopInstrumentation(uri);
})();
optimizeFunctionSync(__codspeed_root_frame__);
measurement.startInstrumentation();
__codspeed_root_frame__();
measurement.stopInstrumentation(uri);
}
console.log(` ✔ Measured ${uri}`);
benchmarkCompletedListeners.forEach((listener) => listener());
Expand Down

0 comments on commit b226f14

Please sign in to comment.