-
Notifications
You must be signed in to change notification settings - Fork 8
Add necessary flags to dump optimized inlining info and fix marker placement in tinybench #83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -9,24 +9,60 @@ import { | |||||||||||||||||||||||||||
| type BenchmarkStats, | ||||||||||||||||||||||||||||
| type Benchmark as CodspeedBenchmark, | ||||||||||||||||||||||||||||
| } from "@codspeed/core"; | ||||||||||||||||||||||||||||
| import { Bench, Fn, Task, TaskResult } from "tinybench"; | ||||||||||||||||||||||||||||
| import { Bench, Fn, Hook, Task, TaskResult } from "tinybench"; | ||||||||||||||||||||||||||||
| import { BaseBenchRunner } from "./shared"; | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| export function setupCodspeedWalltimeBench( | ||||||||||||||||||||||||||||
| bench: Bench, | ||||||||||||||||||||||||||||
| rootCallingFile: string, | ||||||||||||||||||||||||||||
| ): void { | ||||||||||||||||||||||||||||
| const runner = new WalltimeBenchRunner(bench, rootCallingFile); | ||||||||||||||||||||||||||||
| runner.installInstrumentHooks(); | ||||||||||||||||||||||||||||
| runner.setupBenchMethods(); | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| class WalltimeBenchRunner extends BaseBenchRunner { | ||||||||||||||||||||||||||||
| private codspeedBenchmarks: CodspeedBenchmark[] = []; | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| // Carries the window start timestamp from the setup hook to the teardown | ||||||||||||||||||||||||||||
| // hook. Tasks run strictly sequentially, so a single field is enough. | ||||||||||||||||||||||||||||
| private runStart: bigint | null = null; | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| protected getModeName(): string { | ||||||||||||||||||||||||||||
| return "walltime mode"; | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||
| * Drive the instrumentation window from the task's setup/teardown hooks so it | ||||||||||||||||||||||||||||
| * brackets only tinybench's measured loop, excluding warmup and the | ||||||||||||||||||||||||||||
| * statistics computation (`processRunResult`) that surround it. The user's | ||||||||||||||||||||||||||||
| * own hooks are preserved and still run in their original order relative to | ||||||||||||||||||||||||||||
| * the work under test. | ||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||
| public installInstrumentHooks(): void { | ||||||||||||||||||||||||||||
| // `bench.opts` is typed `Readonly`, but tinybench mutates it at runtime and | ||||||||||||||||||||||||||||
| // always resolves `setup`/`teardown` to (at least) a no-op default. | ||||||||||||||||||||||||||||
| const opts = this.bench.opts as { setup: Hook; teardown: Hook }; | ||||||||||||||||||||||||||||
| const userSetup = opts.setup; | ||||||||||||||||||||||||||||
| const userTeardown = opts.teardown; | ||||||||||||||||||||||||||||
|
Comment on lines
+45
to
+47
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| opts.setup = (task, mode) => { | ||||||||||||||||||||||||||||
| const setupResult = userSetup(task, mode); | ||||||||||||||||||||||||||||
| if (mode === "run") { | ||||||||||||||||||||||||||||
| this.runStart = this.openInstrumentWindow(); | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| return setupResult; | ||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||
|
Comment on lines
+49
to
+55
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| opts.teardown = (task, mode) => { | ||||||||||||||||||||||||||||
| if (mode === "run" && task) { | ||||||||||||||||||||||||||||
| this.closeInstrumentWindow(this.getTaskUri(task), this.runStart!); | ||||||||||||||||||||||||||||
| this.runStart = null; | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| return userTeardown(task, mode); | ||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| protected async runTaskAsync(task: Task, uri: string): Promise<void> { | ||||||||||||||||||||||||||||
| // Override the function under test to add a static frame | ||||||||||||||||||||||||||||
| this.wrapTaskFunction(task, true); | ||||||||||||||||||||||||||||
|
|
@@ -37,21 +73,22 @@ class WalltimeBenchRunner extends BaseBenchRunner { | |||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| await mongoMeasurement.start(uri); | ||||||||||||||||||||||||||||
| await this.wrapWithInstrumentHooksAsync(() => task.run(), uri); | ||||||||||||||||||||||||||||
| await task.run(); | ||||||||||||||||||||||||||||
| await mongoMeasurement.stop(uri); | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| this.registerCodspeedBenchmarkFromTask(task); | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| protected runTaskSync(task: Task, uri: string): void { | ||||||||||||||||||||||||||||
| // eslint-disable-next-line @typescript-eslint/no-unused-vars | ||||||||||||||||||||||||||||
| protected runTaskSync(task: Task, _uri: string): void { | ||||||||||||||||||||||||||||
| // Override the function under test to add a static frame | ||||||||||||||||||||||||||||
| this.wrapTaskFunction(task, false); | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| if (this.bench.opts.warmup) { | ||||||||||||||||||||||||||||
| task.warmup(); | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| this.wrapWithInstrumentHooks(() => task.runSync(), uri); | ||||||||||||||||||||||||||||
| task.runSync(); | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| this.registerCodspeedBenchmarkFromTask(task); | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
walltimecase is missing abreakstatement, unlike theanalysiscase above it. While harmless here since there is no subsequent case, the inconsistency can confuse future readers and will tripno-fallthroughlinters.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!