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
<script>
var s = 'abcdefghijklmnopqrstuvwxyz';
var str;
var a = [];
for(var i=0; i<100; i++)
a.push(s);
str=a.join("");
function str_reverse1(str) {
return str.split('').reverse().join('');
}
function str_reverse2(str) {
var result = '',
length = str.length;
while (length--) {
result += str[length];
}
return result;
}
function str_reverse3(str) {
var result = [],
length = str.length,
pad = length;
while (length--) {
result[pad - length] = str[length];
}
return result.join('');
}
function str_reverse4(str) {
var curr, result = str.split('');
for (var i = 0, j = result.length - 1; i < j; i++, j--) {
curr = result[i];
result[i] = result[j];
result[j] = curr;
}
return result.join('');
}
function str_reverse5(str) {
var length = str.length,
result = [];
while (length--) {
result.push(str[length]);
}
return result.join();
}
function str_reverse6(str) {
var length = str.length,
pad = length,
result = new Array(length);
while (length--) {
result[pad - length] = str[length];
}
return result.join('');
}
function str_reverse7(str) {
var tmp = '';
for (var i = str.length - 1; i >= 0; i--) {
tmp += str[i];
}
return tmp;
}
</script>
Ready to run.
Test | Ops/sec | |
---|---|---|
str.split('').reverse().join('') |
| ready |
str_reverse2(str) |
| ready |
str_reverse3(str) |
| ready |
str_reverse4(str) |
| ready |
str_reverse5(str) |
| ready |
str_reverse6(str) |
| ready |
str_reverse7(str) |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.