Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
SPlICE + UNSHIFT vs SORT (10000 items) with Filter
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36
Browser:
Chrome 126
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
SPLICE + UNSHIFT: array 10000 items; itemIndex - 10000
18200.6 Ops/sec
SORT: array 10000 items; itemIndex - 10000
6506.7 Ops/sec
Script Preparation code:
var arr = [...Array(10000)].map((_,i) => i)
Tests:
SPLICE + UNSHIFT: array 10000 items; itemIndex - 10000
let newArr = [...arr] const item = 9999 const filteredItem = newArr.filter((x) => x === 3) const itemIndex = newArr.findIndex((x) => x === filteredItem) console.log('SPLICE + UNSHIFT [0] before', newArr[0]) console.log('SPLICE + UNSHIFT length before', newArr.length) newArr.splice(itemIndex, 1) newArr.unshift(filteredItem) console.log('SPLICE + UNSHIFT [0] after', newArr[0]) console.log('SPLICE + UNSHIFT length after', newArr.length)
SORT: array 10000 items; itemIndex - 10000
let newArr = [...arr] const item = 9999 const itemIndex = newArr.findIndex((x) => x === item) console.log('SORT [0] before', newArr[0]) console.log('SORT length before', newArr.length) newArr = newArr.sort((a, b) => { if (a === item) { return -1 } if (b === item) { return 1 } return 0 }) console.log('SORT [0] after', newArr[0]) console.log('SORT length after', newArr.length)