diff options
Diffstat (limited to 'std/testing/bench.ts')
-rw-r--r-- | std/testing/bench.ts | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/std/testing/bench.ts b/std/testing/bench.ts index 87be641ab..a5e6490ac 100644 --- a/std/testing/bench.ts +++ b/std/testing/bench.ts @@ -187,7 +187,7 @@ export function clearBenchmarks({ */ export async function runBenchmarks( { only = /[^\s]/, skip = /^\s*$/, silent }: BenchmarkRunOptions = {}, - progressCb?: (progress: BenchmarkRunProgress) => void + progressCb?: (progress: BenchmarkRunProgress) => void | Promise<void> ): Promise<BenchmarkRunResult> { // Filtering candidates by the "only" and "skip" constraint const benchmarks: BenchmarkDefinition[] = candidates.filter( @@ -213,7 +213,7 @@ export async function runBenchmarks( }; // Publish initial progress data - publishProgress(progress, ProgressState.BenchmarkingStart, progressCb); + await publishProgress(progress, ProgressState.BenchmarkingStart, progressCb); if (!silent) { console.log( @@ -243,7 +243,7 @@ export async function runBenchmarks( // Init the progress of the running benchmark progress.running = { name, runsCount: runs, measuredRunsMs: [] }; // Publish starting of a benchmark - publishProgress(progress, ProgressState.BenchStart, progressCb); + await publishProgress(progress, ProgressState.BenchStart, progressCb); // Trying benchmark.func let result = ""; @@ -267,7 +267,11 @@ export async function runBenchmarks( // Adding partial result progress.running.measuredRunsMs.push(measuredMs); // Publish partial benchmark results - publishProgress(progress, ProgressState.BenchPartialResult, progressCb); + await publishProgress( + progress, + ProgressState.BenchPartialResult, + progressCb + ); // Resetting the benchmark clock clock.start = clock.stop = NaN; @@ -288,7 +292,11 @@ export async function runBenchmarks( // Clear currently running delete progress.running; // Publish results of the benchmark - publishProgress(progress, ProgressState.BenchResult, progressCb); + await publishProgress( + progress, + ProgressState.BenchResult, + progressCb + ); break; } } @@ -317,7 +325,7 @@ export async function runBenchmarks( // Indicate finished running delete progress.queued; // Publish final result in Cb too - publishProgress(progress, ProgressState.BenchmarkingEnd, progressCb); + await publishProgress(progress, ProgressState.BenchmarkingEnd, progressCb); if (!silent) { // Closing results @@ -340,12 +348,12 @@ export async function runBenchmarks( return benchmarkRunResult; } -function publishProgress( +async function publishProgress( progress: BenchmarkRunProgress, state: ProgressState, - progressCb?: (progress: BenchmarkRunProgress) => void -): void { - progressCb && progressCb(cloneProgressWithState(progress, state)); + progressCb?: (progress: BenchmarkRunProgress) => void | Promise<void> +): Promise<void> { + progressCb && (await progressCb(cloneProgressWithState(progress, state))); } function cloneProgressWithState( |