Skip to content

Commit dafca73

Browse files
committed
chore: capture time inside benchmark operation
1 parent c31ff7c commit dafca73

3 files changed

Lines changed: 16 additions & 6 deletions

File tree

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
1-
import { Effect } from "npm:effect";
2-
import { call } from "../../../mod.ts";
1+
import { Effect, Fiber } from "npm:effect";
2+
import { call, ensure } from "../../../mod.ts";
33
import { scenario } from "./scenario.ts";
44

55
await scenario("effect.startup", function* (_, exit) {
6+
let start = performance.now();
7+
68
const startup = Effect.gen(function* () {
7-
exit(performance.now());
9+
exit(performance.now() - start);
810
yield* Effect.promise(() => Promise.resolve());
911
});
1012

11-
return yield* call(() => Effect.runPromise(startup));
13+
const fiber = Effect.runFork(startup);
14+
15+
yield* ensure(function* () {
16+
yield* call(() => Effect.runPromise(Fiber.interrupt(fiber)));
17+
});
18+
19+
return yield* call(() => Effect.runPromise(Fiber.join(fiber)));
1220
});

tasks/bench/scenarios/effection.startup.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ import { call, type Operation } from "../../../mod.ts";
22
import { scenario } from "./scenario.ts";
33

44
await scenario("effection.startup", function* (_, exit) {
5+
let start = performance.now();
6+
57
function* startup(): Operation<void> {
6-
exit(performance.now());
8+
exit(performance.now() - start);
79
yield* call(() => Promise.resolve());
810
}
911

tasks/bench/scenarios/scenario.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export function scenario(
7171
times.push(time);
7272

7373
if (entryTime) {
74-
entryTimes.push(entryTime - start);
74+
entryTimes.push(entryTime);
7575
}
7676
}
7777

0 commit comments

Comments
 (0)