deno icon indicating copy to clipboard operation
deno copied to clipboard

`Deno.bench` no longer accepts iteration params

Open brycedorn opened this issue 3 years ago • 2 comments

Hi! It looks like the warmup & n params were removed from Deno.bench which could control the number of iterations that run. The last version to include them looks to be v1.20.6.

Was there a reason for this or could they be re-added? Happy to submit a PR to add them back.

brycedorn avatar Feb 04 '23 13:02 brycedorn

The number of warmup iterations was an imprecise way of actually warming up the function. Bench now warms up until the speed reaches an equilibrium, so warm-up is automatic and should be reliable in its effects.

aapoalas avatar Feb 04 '23 14:02 aapoalas

@aapoalas thanks for the quick reply. Warmup precision is good, but shouldn't there be a way to control the number of iterations? I'm benchmarking logic that involves connecting to 3rd party services that have rate-limiting, would be helpful to restrict to a set number of runs.

This is my current workaround but I don't see a reason why the parameter shouldn't still be available:

const maxIterations = 30;
let n = 0;

Deno.bench("n iterations", () => {
    if (n < maxIterations) {        
        console.log('Completed:', n);
    }

    n += 1;
});

brycedorn avatar Feb 04 '23 14:02 brycedorn