mirror of
https://github.com/denoland/deno.git
synced 2025-08-04 19:08:15 +00:00
fix(bench): lower bench time budget when n
is specified (#28454)
Closes #28430
This commit is contained in:
parent
9ea4f82643
commit
ff28ecd91a
2 changed files with 12 additions and 7 deletions
|
@ -241,7 +241,7 @@ const allMaxLength = 10_000_000;
|
|||
let all = new Array(allMaxLength);
|
||||
const lowPrecisionThresholdInNs = 1e4;
|
||||
|
||||
async function benchMeasure(timeBudget, fn, desc, context) {
|
||||
async function benchMeasure(fn, desc, context) {
|
||||
let n = 0;
|
||||
let avg = 0;
|
||||
let wavg = 0;
|
||||
|
@ -251,7 +251,7 @@ async function benchMeasure(timeBudget, fn, desc, context) {
|
|||
|
||||
// warmup step
|
||||
let c = 0;
|
||||
let iterations = desc.warmup > 0 ? desc.warmup : 20;
|
||||
let iterations = desc.warmup >= 0 ? desc.warmup : 20;
|
||||
let budget = 10 * 1e6;
|
||||
|
||||
if (!desc.async) {
|
||||
|
@ -298,7 +298,7 @@ async function benchMeasure(timeBudget, fn, desc, context) {
|
|||
|
||||
// measure step
|
||||
iterations = desc.n > 0 ? desc.n : 10;
|
||||
budget = timeBudget * 1e6;
|
||||
budget = desc.n > 0 ? 10 * 1e6 : 500 * 1e6;
|
||||
|
||||
if (wavg > lowPrecisionThresholdInNs) {
|
||||
if (!desc.async) {
|
||||
|
@ -475,10 +475,8 @@ function wrapBenchmark(desc) {
|
|||
});
|
||||
}
|
||||
|
||||
const benchTimeInMs = 500;
|
||||
const context = createBenchContext(desc);
|
||||
const stats = await benchMeasure(
|
||||
benchTimeInMs,
|
||||
fn,
|
||||
desc,
|
||||
context,
|
||||
|
|
11
cli/tsc/dts/lib.deno.ns.d.ts
vendored
11
cli/tsc/dts/lib.deno.ns.d.ts
vendored
|
@ -1242,9 +1242,16 @@ declare namespace Deno {
|
|||
/** If at least one bench has `only` set to true, only run benches that have
|
||||
* `only` set to `true` and fail the bench suite. */
|
||||
only?: boolean;
|
||||
/** Number of iterations to perform. */
|
||||
/** Number of iterations to perform.
|
||||
* @remarks When the benchmark is very fast, this will only be used as a
|
||||
* suggestion in order to get a more accurate measurement.
|
||||
*/
|
||||
n?: number;
|
||||
/** Number of warmups to do before running the benchmark. */
|
||||
/** Number of warmups to do before running the benchmark.
|
||||
* @remarks A warmup will always be performed even if this is `0` in order to
|
||||
* determine the speed of the benchmark in order to improve the measurement. When
|
||||
* the benchmark is very fast, this will be used as a suggestion.
|
||||
*/
|
||||
warmup?: number;
|
||||
/** Ensure the bench case does not prematurely cause the process to exit,
|
||||
* for example via a call to {@linkcode Deno.exit}.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue