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
test = {
'heroes': 'heroes duende',
'a': 'ab',
'abc': 'xyzabc',
'abc': 'abcxyz',
'abcdefghijklmnopqrstuvwxyz': 'zyxwvutsrqponmlkjihgfedcba'
}
function sift1 (s1, s2) {
if (s1 === s2) return 1;
if (s1 === '' || s2 === '') return 0;
var x = s1 < s2 ? s1 + '/' + s2 : s2 + '/' + s1;
//if (x in sift.cache) return sift.cache[x];
var c1 = 0,
c2 = 0,
l1 = s1.length,
l2 = s2.length,
lcs = 0;
while (c1 < l1 && c2 < l2) {
if (s1.charAt(c1) === s2.charAt(c2)) lcs++;
else {
if (c1 < c2) c2 = c1;
else c1 = c2;
var i = -1;
while (++i < 100) {
if (c1 + i < l1 && s1.charAt(c1 + i) === s2.charAt(c2)) {
lcs++;
c1 += i;
break;
}
if (c2 + i < l2 && s1.charAt(c1) === s2.charAt(c2 + i)) {
lcs++;
c2 += i;
break;
}
}
}
c1++;
c2++;
}
return /*sift.cache[x] = */lcs / ((l1 + l2) / 2);
}
function sift2 (s1, s2) {
if (s1 === s2) return 1;
if (s1 === '' || s2 === '') return 0;
var x = s1 < s2 ? s1 + '/' + s2 : s2 + '/' + s1;
//if (x in sift.cache) return sift.cache[x];
var c1 = 0,
c2 = 0,
l1 = s1.length,
l2 = s2.length,
lcs = 0;
while ((c1 < l1) && (c2 < l2)) {
if (s1.charAt(c1) === s2.charAt(c2)) lcs++;
else {
if (c1 < c2) c2 = c1;
else c1 = c2;
var i = -1;
while (++i < 100) {
if ((c1 + i < l1) && (s1.charAt(c1 + i) === s2.charAt(c2))) {
lcs++;
c1 += i;
break;
}
if ((c2 + i < l2) && (s1.charAt(c1) === s2.charAt(c2 + i))) {
lcs++;
c2 += i;
break;
}
}
}
c1++;
c2++;
}
return /*sift.cache[x] = */lcs / ((l1 + l2) / 2);
}
Ready to run.
Test | Ops/sec | |
---|---|---|
sift1 |
| ready |
sift2 |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.