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
Testing "trim-native" and "trim27" (from rev7) with the following trim functions:
<script>
function trim27(str) {
var c;
for (var i = 0; i < str.length; i++) {
c = str.charCodeAt(i);
if (c == 32 || c == 10 || c == 13 || c == 9 || c == 12) continue; else break;
}
for (var j = str.length - 1; j >= i; j--) {
c = str.charCodeAt(j);
if (c == 32 || c == 10 || c == 13 || c == 9 || c == 12) continue; else break;
}
return str.substring(i, j + 1);
}
function trim_native(str) {
return str.trim(); // should throw is no such function
}
function trim19(str){
var str = str.replace(/^\s\s*/, ''),
ws = /\s/,
i = str.length;
while (ws.test(str.charAt(--i)));
return str.slice(0, i + 1);
}
// Licensed under BSD - http://flesler.blogspot.com/2008/11/fast-trim-function-for-javascript.html
function myBestTrim( str ){
var start = -1,
end = str.length;
while( str.charCodeAt(--end) < 33 );
while( str.charCodeAt(++start) < 33 );
return str.slice( start, end + 1 );
};
var inp = " \n\n \n\n a \n a\n a\n a\n a \n\t\ta\t\ta\njahsdkjahkjshdakjhsdkahskd akhsjdh akjshd kashdkajhsd kajshd \nkauyiuqhwep iasldk qpwoie ad \n askdjaslkdjaslkjdaoiur qowioqwhr aspodiquw ijasod iqwiue pqowipoqiw epoqiwpeo iaslkjdqur \t kjahsdkj hakshd\nkajhdk\nk as d \t\n".split('\n');
function e(f) {
var x = [];
for (i = 0; i < inp.length; i++) {
x.push(f(inp[i]));
}
return x;
}
</script>
Ready to run.
Test | Ops/sec | |
---|---|---|
trim-native |
| ready |
trim27 |
| ready |
trim19 |
| ready |
myBestTrim |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.