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
Fastest way to create a string with n characters
var sm = 10,
md = 100,
lg = 1000,
xl = 2000;
function arrayJoin(len) {
return new Array(len + 1).join('0');
}
function arrayJoinPrototype(len) {
return Array.prototype.join.call({
length: len + 1
}, '0');
}
function stringConcatLoop(len) {
var s = '';
while (len--) s += '0';
return s;
}
function stringConcatDoublerLoop(len) {
var halfLen = len / 2,
char = '0';
while (char.length <= halfLen) char += char;
return char + char.substring(0, len - char.length);
}
function doubler(len) {
var result = "0";
while (result.length < len) result += result;
return result.slice(0, len);
}
function stringReplacer(len) {
return Array(len + 1).toString().replace(/./ig, '0');
}
Ready to run.
Test | Ops/sec | |
---|---|---|
Array Join |
| ready |
Array Join (Prototype) |
| ready |
String Concat Loop |
| ready |
String Concat Doubler Loop |
| ready |
Replace String |
| ready |
Doubler |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.