tinylibs / tinybench

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

fix: use .call for deoptimization #50

Closed Aslemammad closed 11 months ago

Aslemammad commented 1 year ago

Resolves #46

I tried using .call and it worked. but warmup should be used for more accurate results.

Without warmup:

┌─────────┬───────────┬─────────────┬───────────────────┬──────────┬─────────┐
│ (index) │ Task Name │   ops/sec   │ Average Time (ns) │  Margin  │ Samples │
├─────────┼───────────┼─────────────┼───────────────────┼──────────┼─────────┤
│    0    │    'a'    │ '1,668,042' │ 599.505261791414  │ '±0.47%' │ 834022  │
│    1    │    'b'    │  '159,201'  │ 6281.348724802289 │ '±0.36%' │  79601  │
│    2    │    'c'    │  '162,881'  │ 6139.414994407295 │ '±0.09%' │  81441  │
└─────────┴───────────┴─────────────┴───────────────────┴──────────┴─────────┘

With warmup:

┌─────────┬───────────┬───────────┬───────────────────┬──────────┬─────────┐
│ (index) │ Task Name │  ops/sec  │ Average Time (ns) │  Margin  │ Samples │
├─────────┼───────────┼───────────┼───────────────────┼──────────┼─────────┤
│    0    │    'a'    │ '163,825' │ 6104.066796782642 │ '±0.14%' │  81913  │
│    1    │    'b'    │ '164,007' │ 6097.265856596651 │ '±0.09%' │  82004  │
│    2    │    'c'    │ '163,775' │ 6105.922276082101 │ '±0.11%' │  81888  │
└─────────┴───────────┴───────────┴───────────────────┴──────────┴─────────┘
github-actions[bot] commented 1 year ago

size-limit report 📦

Path Size Loading time (3g) Running time (snapdragon) Total time
dist/index.js 2.44 KB (+0.13% 🔺) 49 ms (+0.13% 🔺) 93 ms (-28.62% 🔽) 142 ms
dist/index.cjs 2.69 KB (+0.11% 🔺) 54 ms (+0.11% 🔺) 104 ms (+18.2% 🔺) 158 ms
kurtextrem commented 8 months ago

but warmup should be used for more accurate results

Should the readme reflect this too?

Aslemammad commented 8 months ago

Should the readme reflect this too?

Why not? feel free to open a PR in case you're interested.

exequielbc commented 8 months ago

hi 👋🏽 I wanted to learn about what deoptimization is and why it is needed but couldn't find any resources with a web search (there is plenty of resources for optimization though haha). Could anyone please point me to a resource or explain here? 🙂

Aslemammad commented 8 months ago

Hey @exequielbc! Happy that you're curious, but tbh it's either I don't remember the reason or I just did it randomly and it worked (by benchmarking different solutions)

Sorry for that answer :)