Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(utils): use | 0 instead of Math.floor #3605

Merged
merged 1 commit into from
Nov 2, 2024

Conversation

EdamAme-x
Copy link
Contributor

@EdamAme-x EdamAme-x commented Nov 1, 2024

| 0 is faster than Math.floor

In Node (2x~ faster)

cpu: AMD EPYC 7763 64-Core Processor
runtime: node 20.18.0 (x64-linux)

benchmark              avg (min … max) p75   p99    (min … top 1%)
-------------------------------------- -------------------------------
Use `| 0`                 4.47 ns/iter   4.19 ns █                    
                  (4.17 ns … 59.67 ns)   9.24 ns █▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁
Use `Math.floor`          8.45 ns/iter   6.78 ns █                    
                 (6.56 ns … 382.53 ns)  27.72 ns █▁▁▁▁▁▂▃▁▁▁▁▁▁▁▁▁▁▁▁▁

In Deno (4x~ faster)

runtime: deno 2.0.4 (x86_64-unknown-linux-gnu)

benchmark              avg (min … max) p75   p99    (min … top 1%)
-------------------------------------- -------------------------------
Use `| 0`                 1.57 ns/iter   1.40 ns ▂█                   
                 (1.32 ns … 138.07 ns)   3.28 ns ██▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▂▂▁
Use `Math.floor`          5.72 ns/iter   4.78 ns █                    
                  (4.64 ns … 89.83 ns)  17.58 ns █▁▁▁▁▁▁▁▁▁▂▁▁▁▁▁▁▁▁▁▁

In Bun (2x~ faster)

runtime: bun 1.1.33 (x64-linux)

benchmark              avg (min … max) p75   p99    (min … top 1%)
-------------------------------------- -------------------------------
Use `| 0`                 2.86 ns/iter   2.53 ns █                    
                 (2.52 ns … 233.34 ns)   5.02 ns █▁▁▁▁▁▁▁▁▁▁▁▁▂▂▁▁▁▁▁▁
Use `Math.floor`          5.30 ns/iter   4.80 ns █                    
                  (4.78 ns … 92.85 ns)   9.88 ns █▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁

The author should do the following, if applicable

  • Add tests
  • Run tests
  • bun run format:fix && bun run lint:fix to format the code
  • Add TSDoc/JSDoc to document the code

Copy link

codecov bot commented Nov 1, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 94.71%. Comparing base (4dd8b2b) to head (574f1a5).
Report is 11 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3605   +/-   ##
=======================================
  Coverage   94.71%   94.71%           
=======================================
  Files         158      158           
  Lines        9555     9555           
  Branches     2813     2781   -32     
=======================================
  Hits         9050     9050           
  Misses        505      505           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@yusukebe yusukebe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@yusukebe
Copy link
Member

yusukebe commented Nov 2, 2024

@EdamAme-x

Thanks! Looks good.

@yusukebe yusukebe merged commit e9830c6 into honojs:main Nov 2, 2024
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants