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 str = 'abcdefghijklmnopqrstuvwxyz';
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('');
}
</script>
Ready to run.
Test | Ops/sec | |
---|---|---|
str.split('').reverse().join('') |
| ready |
str_reverse2(str) |
| ready |
str_reverse3(str) |
| ready |
str_reverse4(str) |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.