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
The actual use-case isn't to sort for every insertion. Either you keep a sorted array, or you sort it at the end.
I removed linear search because it's so slow that freezes the browser.
<script>
function findBSearch(n, array) {
var low = 0, high = array.length;
while (low < high) {
var mid = (low + high) >>> 1;
array[mid] < n ? low = mid + 1 : high = mid;
}
return low;
}
</script>
// Pseudo-random data.
// I keep it the same for the sake of comparison.
var input = [];
for(i=0;i<30000;i++) input.push(Math.floor(Math.random()));
Ready to run.
Test | Ops/sec | |
---|---|---|
push() and sort() |
| ready |
Binary search |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.