Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
Feature Requests
FAQ
Register
Log In
Run results for:
Adding to an array with push.apply vs spread vs loop
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:126.0) Gecko/20100101 Firefox/126.0
Browser:
Firefox 126
Operating system:
Windows
Device Platform:
Desktop
Date tested:
2 years ago
Benchmark engine:
Benchmark.js
Adding with Function.prototype.apply on the push method
9.5M/s
Adding with spread
9.4M/s
Adding with loop
8.9M/s
View exact numbers
Test name
Executions per second
✓
Adding with Function.prototype.apply on the push method
9,535,217 Ops/sec
Adding with spread
9,371,289 Ops/sec
Adding with loop
8,887,086 Ops/sec
Tests:
Adding with Function.prototype.apply on the push method
var target_array = []; var new_data = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20]; target_array.push.apply(target_array, new_data)
Adding with spread
var target_array = []; var new_data = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20]; target_array.push(...new_data)
Adding with loop
var target_array = []; var new_data = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20]; for(let i = 0; i < new_data.length; i++){target_array.push(new_data[i])}