var size = 10000;
var arr = [];
for (var i = 0; i < size; i++){
arr.push(i);
}
arr = [];
arr.length = 0;
arr.splice(0, arr.length);
arr = arr.slice(10);
arr.splice(0);
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
Just instantiate new array | |
Set length to zero | |
Splice | |
Slice | |
splice 0 |
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 |
Overview of the Benchmark
The provided JSON represents a JavaScript benchmark that tests how different methods are used to empty an array in JavaScript. The benchmark was designed to answer a question on Stack Overflow, as indicated by the "Description" field.
Options Compared in the Benchmark
The benchmark compares four options for emptying an array:
arr = []
arr.length = 0
arr.splice(0)
arr.slice(10)
Pros and Cons of Each Approach
Library Used
The benchmark does not use any libraries explicitly. However, it's worth noting that some browsers (like Chrome) have built-in optimizations for certain JavaScript features, such as array methods.
Special JS Feature or Syntax
None of the provided benchmark test cases use special JavaScript features or syntax beyond standard ECMAScript.