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
Checking if an value is present in an array. Of course, the value we are searching for has and the position in the array has costs.
<script>
function inArray1(needle, haystack) {
var length = haystack.length;
for (var i = 0; i < length; i++) {
if (haystack[i] == needle) return true;
}
return false;
}
function inArray2(needle, haystack) {
return !!~haystack.join("").indexOf(needle);
}
function inArray3(needle, haystack) {
return !haystack.join("").indexOf(needle) == -1
}
function inArray4(needle, haystack) {
return !haystack.indexOf(needle) == -1
}
var arr = [1, 2, 3, 4, 5, 6, 7],
num = 5;
</script>
Ready to run.
Test | Ops/sec | |
---|---|---|
inArray1 |
| ready |
inArray2 |
| ready |
inArray3 |
| ready |
inArray4 |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.