Run details:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36 Edge/15.15063
Chrome 52
Windows
Other
2025 years ago
Test name Executions per second
while (array.length > 0) { array.pop(); } 26927620.0 Ops/sec
while (array.pop()) {} 34601040.0 Ops/sec
array.length = 0; 18557890.0 Ops/sec
array = []; 24134674.0 Ops/sec
Script Preparation code:
x
 
var array = [];
for(var i = 0; i < 100000; i++){array.push(Math.random());}
Tests:
  • while (array.length > 0) { array.pop(); }

     
    while (array.length > 0) { array.pop(); }
  • while (array.pop()) {}

     
    while (array.pop()) {}
  • array.length = 0;

     
    array.length = 0;
  • array = [];

     
    array = [];