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
faster way to select the nth digit in integer
var testNumbers = [1, 12, 123, 1234, 12345];
function toStringAndCharAt(ntn, number){
return number.toString().charAt(ntn);
}
function plusAndCharAt(ntn, number){
return (number + '').charAt(ntn);
}
function plusAndIndex(ntn, number){
return (number + '')[ntn];
}
function math(ntn, number){
var len = Math.floor( Math.log(number) / Math.LN10 ) - ntn;
return ( (number / Math.pow(10, len)) % 10) | 0;
}
function mathReverse(ntn, number) {
return Math.floor((number / Math.pow(10, ntn)) % 10);
}
Ready to run.
Test | Ops/sec | |
---|---|---|
number.toString().chatAt(ntn) |
| ready |
(number + '').chatAt(ntn) |
| ready |
(number + '')[ntn] |
| ready |
Math |
| ready |
mathReverse |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.