Skip to content

Commit f31ba67

Browse files
committed
make runTimed async
1 parent ef669a4 commit f31ba67

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

src/util/benchRepeat.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ export async function fastestTest<T>(
2424
async function runTracked<T>(fn: () => T): Promise<TimingResult<T>> {
2525
v8.collectGarbage();
2626
const gcTrack = new GarbageTrack();
27-
const { result: wrappedResult, trackId } = gcTrack.watch(() => runTimed(fn));
27+
const { result: wrappedResult, trackId } = await gcTrack.watch(() =>
28+
runTimed(fn)
29+
);
2830
const gcTime = await gcTrack.gcDuration(trackId);
2931
const { result, time } = wrappedResult;
3032
gcTrack.destroy();

src/util/garbageTracking.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,13 @@ export class GarbageTrack {
1414
private periods: WatchPeriod[] = [];
1515

1616
/** look for gc events during the time this function is executing */
17-
watch<T>(fn: () => T): { result: T; trackId: number } {
17+
async watch<T>(fn: () => T): Promise<{
18+
result: Awaited<T>;
19+
trackId: number;
20+
}> {
1821
this.trackId++;
1922
const start = performance.now();
20-
const result = fn();
23+
const result = await fn();
2124
const end = performance.now();
2225
this.periods.push({ trackId: this.trackId, start, end });
2326

src/util/perfUtil.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ export interface TimedResult<T> {
44
}
55

66
/** run a function, recording how long it takes */
7-
export function runTimed<T>(fn: () => T): TimedResult<T> {
7+
export async function runTimed<T>(fn: () => T): Promise<TimedResult<T>> {
88
const start = performance.now();
9-
const result = fn();
9+
const result = await fn();
1010
const time = performance.now() - start;
1111
return { result, time };
1212
}

0 commit comments

Comments
 (0)