Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
sort vs unshift2
(version: 0)
Comparing performance of:
sort vs unshift
Created:
2 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var isObjectPrototype = (prototype) => prototype && 'modelPrototypeId' in prototype; var isModelPrototype = (prototype) => !isObjectPrototype(prototype); var data = [...Array(200)].map((_,i) => i % 2 ? ({ id: i, modelPrototypeId: `mp-${i}` }) : ({ id: i }))
Tests:
sort
data = data.sort((a, b) => { return +isModelPrototype(a) - +isModelPrototype(b); });
unshift
data = data.reduce((acc, curr) => { if (isModelPrototype(curr)) { acc.push(curr); } else { acc.unshift(curr); } return acc; }, []);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
sort
unshift
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
2 years ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36
Browser/OS:
Chrome 124 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
sort
19678.7 Ops/sec
unshift
33999.2 Ops/sec
Related benchmarks:
sort destruct vs sort
lodash uniqBy vs custom uniqBy
slice sort vs sort
slice sort vs spread sort vs sort
slice sort vs spread sort vs sort vs structured sort
Comments
Confirm delete:
Do you really want to delete benchmark?