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
a silly test of palindrome testing techniques
<script>
function f1(str) {
return str === str.split('').reverse().join('');
}
function f2(str) {
var i = str.length - 1;
var k = 0;
while (i > k) {
if (str.charAt(k++) !== str.charAt(i--)) return false;
}
return true;
}
function f3(str) {
var middle = Math.floor(str.length / 2),
l = str.length;
for (var i=0; i<middle; i++) {
if (str.charAt(i) !== str.charAt(l-i-1)) return false;
}
return true;
}
function f4(str) {
for (var i = 0; i < str.length/2 << 0; i++) {
if (str.charAt(i) !== str.charAt(str.length-i-1)) {
return false;
}
}
return true;
}
</script>
var str1 = "abcdefghijklmnopqrstuvwxyzzyxwvutsrqponmlkjihgfedcba";
var str2 = "abcdefghijklmnopqrstuvwxyzyxwvutsrqponmlkjihgfedcba";
var str3 = "abcdefghijklmnopqrstuvwxyzZyxwvutsrqponmlkjihgfedcba";
Ready to run.
Test | Ops/sec | |
---|---|---|
Native strip reverse |
| ready |
While loop character comparison |
| ready |
For loop |
| ready |
For loop improved |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.