Skip to content

Commit

Permalink
fix: measure only script performance if metrics: ['script']
Browse files Browse the repository at this point in the history
If users only want to measure the 'script' performance (i.e they
specified `metrics: ['script']` in their `best.config.js` file),
speed up the tests by making Best avoid adding the extra macrotask
(intended for measuring style/layout) to the benchmark iterations.
  • Loading branch information
sf-v committed Nov 17, 2022
1 parent 39fcff9 commit 6190687
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
15 changes: 15 additions & 0 deletions packages/@best/runner-abstract/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,20 @@ export default abstract class AbstractRunner {
const { benchmarkIterations, benchmarkOnClient, benchmarkMaxDuration, benchmarkMinIterations } = projectConfig;
const definedIterations = Number.isInteger(benchmarkIterations);

let useMacroTaskAfterBenchmark = true;

/*
* If users only want to measure the 'script' performance
* (i.e they specified `metrics: ['script']` in their
* `best.config.js` file), speed up the tests by making
* Best avoid adding the extra macrotask (intended for
* measuring style/layout) to the benchmark iterations.
*/

if (projectConfig.metrics.length === 1 && projectConfig.metrics.includes('script')) {
useMacroTaskAfterBenchmark = false;
}

// For benchmarking on the client or a defined number of iterations duration is irrelevant
const maxDuration = definedIterations ? 1 : benchmarkMaxDuration;
const minSampleCount = definedIterations ? benchmarkIterations : benchmarkMinIterations;
Expand All @@ -91,6 +105,7 @@ export default abstract class AbstractRunner {
minSampleCount,
iterations: benchmarkIterations,
iterateOnClient: benchmarkOnClient,
useMacroTaskAfterBenchmark,
};
}

Expand Down
1 change: 1 addition & 0 deletions packages/@best/types/src/benchmark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export interface BenchmarkRuntimeConfig {
minSampleCount: number;
iterations: number;
iterateOnClient: boolean;
useMacroTaskAfterBenchmark: boolean;
}

export enum BenchmarkMeasureType {
Expand Down

0 comments on commit 6190687

Please sign in to comment.