tinylibs / tinybench

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

Is there a reason that bench.run() doesn't throw? #47

Closed jcbhmr closed 11 months ago

jcbhmr commented 1 year ago

I was scratching my head for a good three hours until I did this:

bench.addEventListener("error", e => reportError(e))

Scenario:

const bench = new Bench()
bench.add("i look fast but i just fail", () => { iDontExist() })
await bench.run()
console.table(bench.table())

Is there a reason that right now throwing inside benchmarks doesn't cause a catastrophic failure? There must be... right? 😅

I think that it would be a good idea to make it so that either:

  1. bench.run() throws
  2. console.error() on any errors

Some kind of user feedback that the superfast speeds they're seeing are actually an error is a good idea. 😊

Aslemammad commented 1 year ago

Yes, because environemnts like Vitest want to handle the error themselves instead of us throwing. We can add an option called throws, that'd also be good.

Aslemammad commented 1 year ago

check #51

jdmarshall commented 11 months ago

I've been dealing with this the last couple of days. If you look at bench.tasks (for instance, when bench.table() is being called) you can see that some of your tests ran 0 times, and the result contains the error it encountered.

It would be better for everyone who is not us if the tests told you when they are blowing up.

Aslemammad commented 11 months ago

I fixed this in the PR and I'll try to merge soon, sorry for the delay!

jdmarshall commented 11 months ago

The extra checks in table() might fix a problem I'm having. cool cool

Aslemammad commented 11 months ago

Happy to hear that @jdmarshall