jsPerf.app is an online JavaScript performance benchmark test runner & jsperf.com mirror. It is a complete rewrite in homage to the once excellent jsperf.com now with hopefully a more modern & maintainable codebase.
jsperf.com URLs are mirrored at the same path, e.g:
https://jsperf.com/negative-modulo/2
Can be accessed at:
https://jsperf.app/negative-modulo/2
Bitwise floor usually works faster than Math.floor, however it produces incorrect results when the 32nd bit integer is set. Bitwise operations also truncate the the values to 32 bits, but that is a different matter.
Obviously, the distribution of numbers will make some impact here. However, since the fast majority of numbers we deal with are small and do not use the 32nd bit, we only test a smaller number.
var val1 = 0x7fffffff;
var val2 = val1 + 0.12345;
var n;
Ready to run.
Test | Ops/sec | |
---|---|---|
Just use floor |
| ready |
Check and use bitwise |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.