测量模型


🌐 Measurement model

每次热身和测量样本都会使用一个新的 BenchContext 调用基准函数一次。该函数必须要么正好调用一次 context.start() 和 context.end(operations),要么正好调用一次 context.record(sample) 来提供一个外部测量的样本。在 start() 之前的设置和在 end() 之后的清理不在测量区域内。返回 Promise 的函数会被等待。

🌐 Each warmup and measured sample invokes the benchmark function once with a fresh BenchContext. The function must either call context.start() and context.end(operations) exactly once, or call context.record(sample) exactly once to provide an externally measured sample. Setup before start() and cleanup after end() are outside the measured region. Promise-returning functions are awaited.

默认情况下,每次样本调用之间都会有一次事件循环。嵌入式运行器可以使用 yieldBetweenSamples 来禁用这一点。运行器按顺序执行基准测试,但它不提供进程隔离。进程中的其他工作、JIT 编译、垃圾回收、CPU 频率变化以及系统负载都可能影响结果。在比较结果时保留原始样本,并且遇到数据噪声大或分布偏斜时,应调查原因,而不是把置信区间当作通过/不通过的标准。

🌐 By default, an event loop turn occurs between sample invocations. An embedded runner can disable this using yieldBetweenSamples. The runner executes benchmarks serially, but it does not provide process isolation. Other work in the process, JIT compilation, garbage collection, CPU frequency changes, and system load can all affect results. Keep raw samples when comparing results and investigate noisy or skewed distributions rather than treating a confidence interval as a pass/fail threshold.