Skip to content

Results are incorrect #10

@ecstrema

Description

@ecstrema

I don't know what causes this, but all results seem completely off-bounds.

Reproduction

/* eslint-disable no-console */
import { Bench } from "tinybench";

const suite = new Bench({ iterations: 100_000 });

suite
  .add("10", () => {
    for (let i = 0; i < 10; i++);
  })
  .add("1 000", () => {
    for (let i = 0; i < 1_000; i++);
  })
  .add("100 000", () => {
    for (let i = 0; i < 100_000; i++);
  });

suite.tasks.forEach((task) => {
  task.addEventListener("complete", () => {
    console.log(`${task.name}\t\t${task.result.mean * 1000}`);
  });
});

await suite.warmup();
await suite.run();

console.table(suite.tasks.map(({ name, result }) => ({ "Task Name": name, "Average Time (ps)": result.mean * 1000, "Variance (ps)": result.variance * 1000 })));

Output:

10              33.51586236828007
1 000           33.56626915780828
100 000         33.56723708981648
┌─────────┬───────────┬───────────────────┬─────────────────────┐
│ (index) │ Task Name │ Average Time (ps) │    Variance (ps)    │
├─────────┼───────────┼───────────────────┼─────────────────────┤
│    0    │   '10'    │ 33.51586236828007 │ 0.13611378835207122 │
│    1    │  '1 000'  │ 33.56626915780828 │ 0.12475075068569264 │
│    2    │ '100 000' │ 33.56723708981648 │ 0.13970421827784552 │
└─────────┴───────────┴───────────────────┴─────────────────────┘

Two things here:

  1. They all seem to take as long, which is not possible.
  2. They all send their "complete" event at the same time.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions