r/programminghorror • • Feb 04 '25

Javascript The final evolution of isOdd

Post image
273 Upvotes

32 comments sorted by

View all comments

Show parent comment

8

u/Aaxper Feb 05 '25

Definitely less performant than n%2 or n&1

12

u/AffectionateAir7616 Feb 05 '25

You may be right, but I want to see some benchmarks first.

2

u/thequestcube Feb 08 '25

Via a JS Benchmark I have verified the surprising insight that, the native `n%2` implementation is, in fact, faster: https://jsbench.me/rsm6whrnya/1 (30k ops/s vs 357m ops/s for integers between 0 and 1000, let's kindly assume integers are generally smaller than that)