Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
empty an array in JavaScript?
Based on question on http://stackoverflow.com/questions/1232040/how-do-i-empty-an-array-in-javascript
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36
Browser:
Chrome 135
Operating system:
Windows
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
Just instantiate new array
7693743.5 Ops/sec
Set length to zero
26787834.0 Ops/sec
Splice
37747808.0 Ops/sec
Slice
6479494.0 Ops/sec
splice 0
43728360.0 Ops/sec
Script Preparation code:
var size = 10000; var arr = []; for (var i = 0; i < size; i++){ arr.push(i); }
Tests:
Just instantiate new array
arr = [];
Set length to zero
arr.length = 0;
Splice
arr.splice(0, arr.length);
Slice
arr = arr.slice(10);
splice 0
arr.splice(0);