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

refactor: compare with undefined directly #3602

Merged
merged 1 commit into from
Nov 1, 2024

Conversation

exoego
Copy link
Contributor

@exoego exoego commented Oct 31, 2024

It's a bit shorter and more concise (Hono repo uses it widely over typeof).

Performance-wise, no changes.

import { bench, run } from 'mitata'

const v = 'str'

bench('typeof ', () => {
  const s = typeof v === 'undefined'
})

bench('direct', () => {
  const s = v === undefined
})

await run()
runtime: node 22.4.0 (arm64-darwin)

benchmark              avg (min … max) p75   p99    (min … top 1%)
-------------------------------------- -------------------------------
typeof                   96.02 ps/iter 101.56 ps           █           !
                 (71.04 ps … 52.26 ns) 111.82 ps ▁▁▁▁▁▁▁▁▁▁█▁▁▁▁█▁▁▁▁▁
direct                   96.73 ps/iter 101.81 ps           █    ▂      !
                  (71.04 ps … 9.09 ns) 112.06 ps ▁▁▁▁▁▁▁▁▁▁█▁▁▁▁█▁▁▁▁▁
runtime: bun 1.1.33 (arm64-darwin)

benchmark              avg (min … max) p75   p99    (min … top 1%)
-------------------------------------- -------------------------------
typeof                   90.79 ps/iter 101.56 ps         █   ▂   ▂     !
                 (61.04 ps … 10.29 ns) 112.06 ps ▁▁▁▁▁▁▁▁█▁▁▁█▁▁▁█▁▁▁▁
direct                   90.38 ps/iter 101.56 ps           █         ▂ !
                  (61.04 ps … 7.02 ns) 101.81 ps ▁▁▁▁▁▁▁▁▁▁█▁▁▁▁▇▁▁▁▁█
runtime: deno 2.0.4 (aarch64-apple-darwin)

benchmark              avg (min … max) p75   p99    (min … top 1%)
-------------------------------------- -------------------------------
typeof                   88.86 ps/iter  91.55 ps           ▂    █      !
                 (61.04 ps … 12.07 ns) 101.81 ps ▁▁▁▁▁▁▁▁▁▁█▁▁▁▁█▁▁▁▁▁
direct                   89.30 ps/iter  91.55 ps                █      !
                 (61.04 ps … 10.83 ns) 101.81 ps ▁▁▁▁▁▁▁▁▁▁█▁▁▁▁█▁▁▁▁▁

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 Oct 31, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 94.71%. Comparing base (4dd8b2b) to head (8c4fd2d).
Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3602   +/-   ##
=======================================
  Coverage   94.71%   94.71%           
=======================================
  Files         158      158           
  Lines        9555     9555           
  Branches     2813     2798   -15     
=======================================
  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 1, 2024

@exoego Thanks!

@yusukebe yusukebe merged commit 1af7e58 into honojs:main Nov 1, 2024
16 checks passed
@exoego exoego deleted the direct-undefined branch November 1, 2024 01:22
TinsFox pushed a commit to TinsFox/hono that referenced this pull request Nov 11, 2024
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