Skip to content

First bench is always slower. Need warmup? #22

Open
@skratchdot

Description

@skratchdot

The first bench call always seems to be slower than other tests. I've included a simple test case below.

benchmark.js:

require('matcha');
[1, 2, 3, 4].forEach((num) => {
  suite(`Benchmark #${num}`, () => {
    bench('empty', () => {});
    bench('empty', () => {});
  });
});

command line:

npm install -g matcha
matcha ./benchmark.js

output:

                      Benchmark #1
     414,441,918 op/s » empty
     126,934,245 op/s » empty

                      Benchmark #2
     130,458,368 op/s » empty
     132,597,178 op/s » empty

                      Benchmark #3
     132,507,794 op/s » empty
     131,705,064 op/s » empty

                      Benchmark #4
     135,100,324 op/s » empty
     131,982,266 op/s » empty


  Suites:  4
  Benches: 8
  Elapsed: 10,695.31 ms

I would expect all the benchmarks to execute around the same amount of time.

Thanks for this library btw!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions