Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Sorted vs unsorted Array sort
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (X11; CrOS x86_64 14541.0.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36
Browser:
Chrome 126
Operating system:
Chrome OS 14541.0.0
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
Unsorted
216.2 Ops/sec
Sorted with check
23828.3 Ops/sec
Sorted without check
2419.5 Ops/sec
Unsorted with check
175.0 Ops/sec
Script Preparation code:
var arr1 = []; for(let i = 0; i < 10000; i++) { arr1.push(Math.floor(Math.random() * 5000)); } var arr2 = arr1.slice(0); arr2.sort((a, b) => a - b);
Tests:
Unsorted
var toSort = arr1.slice(0); toSort.sort((a, b) => a - b);
Sorted with check
var toSort = arr2.slice(0); let lastEntry; let isSorted = true; for(const entry of toSort) { if(lastEntry != null && entry < lastEntry) { isSorted = false; break; } lastEntry = entry; } if(!isSorted) { toSort.sort((a, b) => a - b); }
Sorted without check
var toSort = arr2.slice(0); toSort.sort((a, b) => a - b);
Unsorted with check
var toSort = arr1.slice(0); let lastEntry; let isSorted = true; for(const entry of toSort) { if(lastEntry != null && entry < lastEntry) { isSorted = false; break; } lastEntry = entry; } if(!isSorted) { toSort.sort((a, b) => a - b); }