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 for presence of multiple values in an array. First, using Array.indexOf(). Second, using a bitmask.
<script>
// Array setup
var haystack1 = ["a", "b", "c", "d", "e"];
var needles1 = ["a", "c", "e"];
// Bitmask setup
var opts = {
"a": 1,
"b": 2,
"c": 4,
"d": 8,
"e": 16,
"f": 32,
"g": 64,
"h": 128
};
var haystack2 = opts.a | opts.b | opts.c | opts.d | opts.e;
var needles2 = opts.a | opts.c | opts.e;
var haystack3 = {};
haystack3[opts.a] = true;
haystack3[opts.b] = true;
haystack3[opts.c] = true;
haystack3[opts.d] = true;
haystack3[opts.e] = true;
var needles3 = {};
needles3[opts.a] = true;
needles3[opts.c] = true;
needles3[opts.e] = true;
</script>
Ready to run.
Test | Ops/sec | |
---|---|---|
Array search |
| ready |
Bitmask search |
| ready |
Object lookup |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.