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
There are lots of ways to zero-pad a number in JavaScript. Which is fastest?
This edition tries to optimize the functions without changing their algorithms.
/**
* Pad a number with leading zeros to "pad" places:
*
* @param n: The number to pad
* @param l: The maximum number of leading zeros
*/
function padMath(n, l) {
var x = +("1E" + l); // 10^l
return n < x ? ("" + (x + n)).substr(1) : "" + n
}
function padLoop(n, l) {
var s = '' + n;
while (s.length < l) {
s = '0' + s;
}
return s;
}
Ready to run.
Test | Ops/sec | |
---|---|---|
Math |
| ready |
Loop |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.