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
// s1 is a match
// s2 fails on first char
// s3 fails on second char
var s1 = "okodjdkdjdsllsdkddkdkdkkdkdloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremlorem";
var s2 = "odjdkdjdsllsdkddkdkdkkdkdloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremok";
var s3 = "dkjdkdjdsllsdkddkdkdkkdkdloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremloremlorem";
/* ignore buggy implementation
function startsWith(s,starter) {
// BUG: Will crash if s.length is less than starter.length.
for (var i = 0, cur_c; i < starter.length; i++) {
cur_c = starter[i];
if (s[i] !== starter[i]) {
return false;
}
}
return true;
}
*/
function startsWith2(str, prefix) {
if (str.length < prefix.length)
return false;
for (var i = prefix.length - 1;
(i >= 0) && (str[i] === prefix[i]); --i)
continue;
return i < 0;
}
function startsWith3(str, prefix) {
var length = prefix.length;
if (str.length < length)
return false;
for (var i = 0;
(i < length) && (str[i] === prefix[i]); ++i)
continue;
return i === length;
}
function startsWith4(s, starter) {
var prefixlen = starter.length;
if (s.length < prefixlen)
return false;
var i = 0;
while (i < prefixlen && s[i] === starter[i]) {
++i;
}
return (i === prefixlen);
}
function startsWith5(s, starter) {
var i = starter.length;
while (i--)
if (s.charAt(i) !== starter.charAt(i))
return false;
return true;
}
// github.com/tunnckoCore
function startsWithWhile(a, b) {
var i = b.length;
if (a.length < i) {
return false;
}
while (i--) {
if (a[i] !== b[i]) {
return false;
}
}
return true;
}
Ready to run.
Test | Ops/sec | |
---|---|---|
indexOf |
| ready |
lastIndexOf |
| ready |
startsWith2 |
| ready |
startsWith3 |
| ready |
slice |
| ready |
startsWith4 |
| ready |
startsWithWhile |
| ready |
string.startsWith |
| ready |
string.substring |
| ready |
startsWith5 |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.