tinylibs / tinybench

🔎 A simple, tiny and lightweight benchmarking library!

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Document how to retrieve results

ecstrema opened this issue · comments

Add a working example in readme

The current example does the test, but doesn't log nor output anything to a file. Trying it was very deceiving, although after some research, the lib seems great!

Original issue

Reproduction:

// test.js
import { Bench } from "tinybench";

const bench = new Bench({ time: 100 });

bench
  .add("Test tinybench", () => {
    let a = 8;
    let b = 1;
    const c = a;
    a = b;
    b = c;
  });

console.log(await bench.run());
node test,js

Output:

[ m {} ]

Expected output:

Benchmark results?

I've tried as CJS too, which wasn't supported because of top-level await.

$ node --version
v16.14.2

First time using a benchmarking lib here.

So apparently i need to listen to "cycle" event.

Are there any docs for it?

I suggest the Readme sample to be a working example.

You do not need the cycle event, it's for listening!

to see the result as mentioned in the docs, you can try accessing Task.result (with bench.tasks, bench.getTask, ...) property after bench.run.

You can write your understandings in the docs and I'll merge it.

You can write your understandings in the docs and I'll merge it.

sounds good