From 6190687cce0559f1ed7678d70763c911a0f96610 Mon Sep 17 00:00:00 2001 From: sf-v Date: Wed, 16 Nov 2022 23:13:27 -0800 Subject: [PATCH] fix: measure only `script` performance if `metrics: ['script']` 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. --- packages/@best/runner-abstract/src/index.ts | 15 +++++++++++++++ packages/@best/types/src/benchmark.ts | 1 + 2 files changed, 16 insertions(+) diff --git a/packages/@best/runner-abstract/src/index.ts b/packages/@best/runner-abstract/src/index.ts index f41df59b..eb3ed26c 100644 --- a/packages/@best/runner-abstract/src/index.ts +++ b/packages/@best/runner-abstract/src/index.ts @@ -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; @@ -91,6 +105,7 @@ export default abstract class AbstractRunner { minSampleCount, iterations: benchmarkIterations, iterateOnClient: benchmarkOnClient, + useMacroTaskAfterBenchmark, }; } diff --git a/packages/@best/types/src/benchmark.ts b/packages/@best/types/src/benchmark.ts index 046737bf..a0dde78b 100644 --- a/packages/@best/types/src/benchmark.ts +++ b/packages/@best/types/src/benchmark.ts @@ -17,6 +17,7 @@ export interface BenchmarkRuntimeConfig { minSampleCount: number; iterations: number; iterateOnClient: boolean; + useMacroTaskAfterBenchmark: boolean; } export enum BenchmarkMeasureType {