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
testing speedup of using native sort functions vs manually sorting a very small array
<script>
function toSorteded(item) {
const requiredSizes = [2.3, 2.3, 4];
const providedSizes = [item.length, item.width, item.height].toSorted();
return requiredSizes.every((e, i) => {return providedSizes.at(i) === e});
}
function insertionSorted(item) {
const requiredSizes = [2.3, 2.3, 4];
const providedSizes = [item.length, item.width, item.height];
// insertion sort
providedSizes.forEach((curr, i, a) => {
if (i !== 0) {
let end = i-1;
while (end >= 0 && a.at(end) > curr) {
a[end + 1] = a[end];
--end;
}
a[end + 1] = curr;
}
});
return requiredSizes.every((e, i) => {return providedSizes.at(i) === e});
}
function manualed(item) {
function swap(arr, a, b) {
let tmp = arr[a];
arr[a] = arr[b];
arr[b] = tmp;
}
const requiredSizes = [2.3, 2.3, 4];
const providedSizes = [item.length, item.width, item.height];
// [4, 2.3, 2.3]
if (providedSizes.at(0) === 4) swap(providedSizes, 0, 2)
// [2.3, 4, 2.3]
else if (providedSizes.at(1) === 4) swap(providedSizes, 1, 2)
return requiredSizes.every((e, i) => {return providedSizes.at(i) === e});
}
const a = {length: 4, width: 2.3, height: 2.3};
const b = {length: 2.3, width: 4, height: 2.3};
const c = {length: 2.3, width: 2.3, height: 4};
</script>
Ready to run.
Test | Ops/sec | |
---|---|---|
using toSorted() |
| ready |
insertion sort |
| ready |
manually sorting |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.