Skip to content

Commit 9f01c77

Browse files
chore: test
1 parent e31ee8b commit 9f01c77

File tree

3 files changed

+24
-22
lines changed

3 files changed

+24
-22
lines changed

packages/tinybench-plugin/src/instrumented.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ class InstrumentedBenchRunner extends BaseBenchRunner {
4848
await mongoMeasurement.start(uri);
4949

5050
global.gc?.();
51-
await this.wrapWithInstrumentHooksAsync(
52-
this.wrapFunctionWithFrame(fn, true),
53-
uri
54-
);
51+
await this.wrapFunctionWithFrame(
52+
this.wrapWithInstrumentHooksAsync(fn, uri),
53+
true
54+
)();
5555

5656
await mongoMeasurement.stop(uri);
5757
await fnOpts?.afterEach?.call(task, "run");
@@ -66,7 +66,8 @@ class InstrumentedBenchRunner extends BaseBenchRunner {
6666
fnOpts?.beforeAll?.call(task, "run");
6767
fnOpts?.beforeEach?.call(task, "run");
6868

69-
this.wrapWithInstrumentHooks(this.wrapFunctionWithFrame(fn, false), uri);
69+
global.gc?.();
70+
this.wrapFunctionWithFrame(this.wrapWithInstrumentHooks(fn, uri), false)();
7071

7172
fnOpts?.afterEach?.call(task, "run");
7273
fnOpts?.afterAll?.call(task, "run");

packages/tinybench-plugin/src/shared.ts

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -38,23 +38,24 @@ export abstract class BaseBenchRunner {
3838
return this.bench.tasks;
3939
}
4040

41-
protected wrapWithInstrumentHooks<T>(fn: () => T, uri: string): T {
42-
InstrumentHooks.startBenchmark();
43-
const result = fn();
44-
InstrumentHooks.stopBenchmark();
45-
InstrumentHooks.setExecutedBenchmark(process.pid, uri);
46-
return result;
41+
protected wrapWithInstrumentHooks(fn: Fn, uri: string): Fn {
42+
return () => {
43+
InstrumentHooks.startBenchmark();
44+
const result = fn();
45+
InstrumentHooks.stopBenchmark();
46+
InstrumentHooks.setExecutedBenchmark(process.pid, uri);
47+
return result;
48+
};
4749
}
4850

49-
protected async wrapWithInstrumentHooksAsync(
50-
fn: Fn,
51-
uri: string
52-
): Promise<unknown> {
53-
InstrumentHooks.startBenchmark();
54-
const result = await fn();
55-
InstrumentHooks.stopBenchmark();
56-
InstrumentHooks.setExecutedBenchmark(process.pid, uri);
57-
return result;
51+
protected wrapWithInstrumentHooksAsync(fn: Fn, uri: string): Fn {
52+
return async () => {
53+
InstrumentHooks.startBenchmark();
54+
const result = await fn();
55+
InstrumentHooks.stopBenchmark();
56+
InstrumentHooks.setExecutedBenchmark(process.pid, uri);
57+
return result;
58+
};
5859
}
5960

6061
protected abstract getModeName(): string;

packages/tinybench-plugin/src/walltime.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class WalltimeBenchRunner extends BaseBenchRunner {
3535
}
3636

3737
await mongoMeasurement.start(uri);
38-
await this.wrapWithInstrumentHooksAsync(() => task.run(), uri);
38+
await this.wrapWithInstrumentHooksAsync(task.run, uri)();
3939
await mongoMeasurement.stop(uri);
4040

4141
this.registerCodspeedBenchmarkFromTask(task);
@@ -49,7 +49,7 @@ class WalltimeBenchRunner extends BaseBenchRunner {
4949
task.warmup();
5050
}
5151

52-
this.wrapWithInstrumentHooks(() => task.runSync(), uri);
52+
this.wrapWithInstrumentHooks(task.runSync, uri)();
5353

5454
this.registerCodspeedBenchmarkFromTask(task);
5555
}

0 commit comments

Comments
 (0)