Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Every Third Element
(version: 0)
Comparing performance of:
Push to new array vs Splice vs Filter
Created:
9 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
function fillArrayWithNumbers(n) { var arr = Array.apply(null, Array(n)); return arr.map(function (x, i) { return i }); } var sourceArray = fillArrayWithNumbers(1000);
Tests:
Push to new array
var targetArray = []; for (var i = 0; i < sourceArray.length; i = i+3) { targetArray.push(sourceArray[i]); };
Splice
for(var i = 0; i < sourceArray.length; i++) { sourceArray.splice(i+1,2); }
Filter
var targetArray = sourceArray.filter(function(_, i) { return (i % 3 == 0); })
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
Push to new array
Splice
Filter
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Related benchmarks:
filling
fill vs map
Create New Array & Fill it
fill array with value: map(callback) vs fill(value) 2
fill test
Comments
Confirm delete:
Do you really want to delete benchmark?