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
Compare various ways of rounding.
var somenum = -500 + (Math.random() * 1000), rounded = 1000;
var round, or, not, left, result;
round = Math.round(somenum);
or = (somenum + (somenum > 0 ? .5 : -.5)) | 0;
not = ~~ (somenum + (somenum > 0 ? .5 : -.5));
left = (somenum + (somenum > 0 ? .5 : -.5)) << 0;
if(round == or && or == not && not == left) result = ('all values = '+round+' from: '+somenum);
else result = (['values do not match!','round:'+round,'or'+or,'not'+not,'left'+left, 'from:'+somenum].join('; '));
if(window.console && console.log) console.log(result);
Ready to run.
| Test | Ops/sec | |
|---|---|---|
| Math.round | | ready |
| bitwise NOT | | ready |
| bitwise OR | | ready |
| bitwise left shift | | ready |
| Math.round 2 | | ready |
| bitwise NOT 2 | | ready |
| bitwise OR 2 | | ready |
| bitwise left shift 2 | | ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.