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
function leftpad(str, len, ch) {
str = String(str);
var i = -1;
if (!ch && ch !== 0) ch = ' ';
len = len - str.length;
while (++i < len) {
str = ch + str;
}
return str;
}
function leftpad2(str, len, ch) {
if (!ch && ch !== 0) ch = ' ';
return ('' + ch).repeat(Math.max(0, len - str.length)) + str
}
function leftpad3(str, len, ch) {
str = ''+str;
if (!ch && ch !== 0) ch = ' ';
return new Array(Math.max(0, len - str.length + 1)).join(ch) + str;
}
function leftpad4(str, len, ch) {
if (!ch && ch !== 0) ch = ' ';
var cnt = len - str.length;
var pad = '';
while (1) {
if (cnt & 1) pad += ch;
cnt >>= 1
if (cnt) ch += ch;
else break;
}
return pad + str;
}
function leftpad5(str, len, ch) {
if (!ch && ch !== 0) ch = ' ';
var pad = '';
for(len -= str.length; len>0; --len) pad = pad + ch;
return pad + str;
}
Ready to run.
Test | Ops/sec | |
---|---|---|
while loop |
| ready |
repeat and slice |
| ready |
array join |
| ready |
haozishu |
| ready |
loop pad build |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.