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
function IndexOf(sub, str) {
return str.indexOf(sub);
}
function SubstringSearch(sub, str) {
var i, j, k, n = sub.length,
N = str.length - n + 1;
for (i = 0; i < N; i++) {
j = i;
k = i + n;
while (j < k && str.charAt(j) === sub.charAt(j - i)) j++;
if (j === k) return j - n;
}
return -1;
}
function KMPsubstringSearch(p, s) {
var i, j, M = p.length,
N = s.length,
d = [];
// Вычисление префикс-функции
d[0] = 0;
for (i = 1, j = 0; i < M; i++) {
while (j > 0 && p[j] !== p[i]) j = d[j - 1];
if (p[j] === p[i]) j++;
d[i] = j;
}
// Поиск
for (i = 0, j = 0; i < N; i++) {
while (j > 0 && p[j] !== s[i]) j = d[j - 1];
if (p[j] === s[i]) j++;
if (j === M) return i - j + 1;
}
return -1;
}
Ready to run.
Test | Ops/sec | |
---|---|---|
IndexOf |
| ready |
SubstringSearch |
| ready |
KMPsubstringSearch |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.