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
'use strict';
if (!String.prototype.contains) {
String.prototype.contains = function(searchString) {
return this.indexOf(searchString) !== -1;
};
}
function boyer_moore_horspool(haystack, needle) {
var badMatchTable = {};
var maxOffset = haystack.length - needle.length;
var offset = 0;
var last = needle.length - 1;
var scan;
// Generate the bad match table, which is the location of offsets
// to jump forward when a comparison fails
Array.prototype.forEach.call(needle, function (char, i) {
badMatchTable[char] = last - i;
});
// Now look for the needle
while (offset <= maxOffset) {
// Search right-to-left, checking to see if the current offset at
// needle and haystack match. If they do, rewind 1, repeat, and if we
// eventually match the first character, return the offset.
for (scan=last; needle[scan] === haystack[scan+offset]; scan--) {
if (scan === 0) {
return offset;
}
}
offset += badMatchTable[haystack[offset + last]] || last;
}
return -1;
}
var string = 'foobarfoobar';
Ready to run.
Test | Ops/sec | |
---|---|---|
indexOf |
| ready |
contains |
| ready |
~string.indexOf |
| ready |
!== |
| ready |
boyer_moore_horspool |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.