Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
Feature Requests
FAQ
Register
Log In
Run results for:
JS unshift vs splice vs unshift + splice (3 possibilities) FINAL RESULT!
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36 OPR/114.0.0.0
Browser:
Opera 114
Operating system:
Linux
Device Platform:
Desktop
Date tested:
one year ago
Benchmark engine:
Benchmark.js
unshift with Splice
2.8M/s
Splice with findIndex
43K/s
Unshift with find
15K/s
View exact numbers
Test name
Executions per second
✓
unshift with Splice
2,809,842 Ops/sec
Splice with findIndex
42,832 Ops/sec
Unshift with find
14,521 Ops/sec
Script Preparation code:
var data1 = []; for(i=0; i<10000; i++){data1.push(i);} var data2 = []; for(i=0; i<10000; i++){data2.push(i);} var data3 = []; for(i=0; i<10000; i++){data2.push(i);}
Tests:
Unshift with find
const rest = data1.filter(item => item !== 500); rest.unshift(data1.find(item => item == 500)); return rest;
Splice with findIndex
const cautelarPosition = data2.findIndex(item => item == 500); data2.splice(0, 0, data2.splice(cautelarPosition, 1)[0]); return data2;
unshift with Splice
const cautelarIndex = data3.findIndex(item => item == 500); data3.unshift(data3.splice(cautelarIndex, 1)[0]); return data3;