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
I saw http://stackoverflow.com/questions/1267283/how-can-i-create-a-zerofilled-value-using-javascript and I was just curious about performances.
<script>
function zeroFill_Array(number, width) {
var str = number.toString();
var remWidth = width - str.length;
if (remWidth > 0) {
return new Array(remWidth + (/\./.test(str) ? 2 : 1)).join('0') + str;
}
return str;
}
function zeroFill_While(number, width) {
var str = number.toString();
var remWidth = width - str.length;
while (--remWidth >= 0) {
str = "0" + str;
}
return str;
}
</script>
Ready to run.
Test | Ops/sec | |
---|---|---|
Zerofill_array 5 |
| ready |
Zerofill_while 5 |
| ready |
Zerofill_array 100 |
| ready |
Zerofill_while 100 |
| ready |
Zerofill_array 10000 |
| ready |
Zerofill_while 10000 |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.