Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
Feature Requests
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
Benchmark engine:
Benchmark.js
splice 0
43.7M/s
Splice
37.7M/s
Set length to zero
26.8M/s
Just instantiate new array
7.7M/s
Slice
6.5M/s
View exact numbers
Test name
Executions per second
✓
splice 0
43,728,360 Ops/sec
Splice
37,747,808 Ops/sec
Set length to zero
26,787,834 Ops/sec
Just instantiate new array
7,693,744 Ops/sec
Slice
6,479,494 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);