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
<script src="https://cdn.jsdelivr.net/npm/lodash@4.17.21/lodash.min.js"></script>
// generate 10k ordered elements
const range = _.range(10000);
// drop an element with 33.33% chance
const _1_3 = 1 / 3;
const values = _.filter(range, () => Math.random() > _1_3);
const testCases = _.shuffle(_.map(range, () => _.random(10000)));
function binarySearchV1(val, ar) {
let i = 0;
let j = ar.length - 1;
while (i <= j) {
const k = Math.floor((i + j) / 2);
if (ar[k] < val) {
i = k + 1;
} else if (ar[k] > val) {
j = k - 1;
} else {
return k;
}
}
return i;
}
function binarySearchV2(val, ar) {
let i = 0;
let j = ar.length - 1;
while (i <= j) {
const k = ((i + j) / 2) | 0;
if (ar[k] === val) {
return k;
} else if (ar[k] < val) {
i = k + 1;
} else {
j = k - 1;
}
}
return i;
}
Ready to run.
Test | Ops/sec | |
---|---|---|
Standard |
| ready |
Bitwise floor |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.