Skip to content
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

feat(benchmark infra) Add beforeEachBatchAsync callback #23391

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions tools/benchmark/src/Configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,7 @@ export interface BenchmarkTimingOptions {
}

/**
* Set of options that can be provided to a benchmark. These options generally align with the BenchmarkJS options type;
* you can see more documentation {@link https://benchmarkjs.com/docs#options | here}.
* Operations that can be performed on a per-batch basis
* @public
*/
export interface OnBatch {
Expand All @@ -223,6 +222,16 @@ export interface OnBatch {
* iterations per batch.
*/
beforeEachBatch?: () => void;

/**
* Executes Async code before the start of each batch. This has the same semantics as benchmarkjs's `onCycle`:
* https://benchmarkjs.com/docs/#options_onCycle
*
* @remarks
* Beware that batches run `benchmarkFn` more than once: a typical micro-benchmark might involve 10k
* iterations per batch.
*/
beforeEachBatchAsync?: () => Promise<void>;
}

/**
Expand Down
6 changes: 3 additions & 3 deletions tools/benchmark/src/runBenchmark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ export async function runBenchmarkAsync(
await doBatchAsync(
state.iterationsPerBatch,
args.benchmarkFnAsync,
args.beforeEachBatch,
args.beforeEachBatchAsync,
),
)
) {
Expand Down Expand Up @@ -277,9 +277,9 @@ function doBatch(
async function doBatchAsync(
iterationCount: number,
f: () => Promise<unknown>,
beforeEachBatch: undefined | (() => void),
beforeEachBatchAsync: undefined | (() => Promise<void>),
): Promise<number> {
beforeEachBatch?.();
await beforeEachBatchAsync?.();
let i = iterationCount;
const before = timer.now();
while (i--) {
Expand Down
Loading