tinylibs / tinybench

🔎 A simple, tiny and lightweight benchmarking library!
MIT License
1.73k stars 36 forks source link

Error while Benchmark Execution #68

Closed dkbhadeshiya closed 5 months ago

dkbhadeshiya commented 8 months ago

Hi,

I have been trying to run a benchmark on crypto.randomUUID vs uuid.v4() function.

I hit the following error:

[redacted]/test-bench/node_modules/tinybench/dist/index.cjs:386
      "ops/sec": parseInt(e.hz.toString(), 10).toLocaleString(),
                               ^

TypeError: Cannot read properties of undefined (reading 'toString')
    at [redacted]/test-bench/node_modules/tinybench/dist/index.cjs:386:32
    at Array.map (<anonymous>)
    at u.table ([redacted]/test-bench/node_modules/tinybench/dist/index.cjs:384:23)
    at [redacted]/test-bench/uuid.js:11:25

Node.js v21.5.0

Here is my sample script which I am using to do the testing:

const { Bench } = require('tinybench');
const { v4 } = require('uuid');

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

bench
  .add('Generate ID', () => {
    v4();
  });
bench.run().then(() => {
    console.table(bench.table());
})
dkbhadeshiya commented 8 months ago

Same behaviour happened while using crypto.randomUUID() function.

[redacted]/test-bench/node_modules/tinybench/dist/index.cjs:386
      "ops/sec": parseInt(e.hz.toString(), 10).toLocaleString(),
                               ^

TypeError: Cannot read properties of undefined (reading 'toString')
    at [redacted]/test-bench/node_modules/tinybench/dist/index.cjs:386:32
    at Array.map (<anonymous>)
    at u.table ([redacted]/test-bench/node_modules/tinybench/dist/index.cjs:384:23)
    at [redacted]/test-bench/crypt-uuid.js:11:25

Node.js v21.5.0

Script for testing crypto.randomUUID()

const { Bench } = require('tinybench');
const { randomUUID } = require('crypto');

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

bench
  .add('Generate ID', () => {
    randomUUID();
  });
bench.run().then(() => {
    console.table(bench.table());
})
sirenkovladd commented 8 months ago

Looks like this should be fixed by now https://github.com/tinylibs/tinybench/commit/ab950e03ccac536b4d382433f6dc410ad3360933#diff-c19b4a9aa70c935caded8b62cdaf76680cf0034fdc146a383a60ed2607c854c9R164-R167

@Aslemammad, could you release a new version?

Aslemammad commented 8 months ago

Looks like this should be fixed by now https://github.com/tinylibs/tinybench/commit/ab950e03ccac536b4d382433f6dc410ad3360933#diff-c19b4a9aa70c935caded8b62cdaf76680cf0034fdc146a383a60ed2607c854c9R164-R167

@Aslemammad, could you release a new version?

Thank you so much, do you want to be a member of tinylibs?