Array emptying performance

Benchmark created on


Setup

const arrayLength = 10000;
const defaultValue = 0; // You can replace this with any default value you want

const newArray = new Array(arrayLength).fill(defaultValue);

Test runner

Ready to run.

Testing in
TestOps/sec
a = []
a = []; // 37% slower
ready
length = 0

a.length = 0; // 89% slower
ready
poppage
// 97% slower
while (a.length > 0) {
    a.pop();
} // Fastest
ready
splice

a.splice(0, a.length)  
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.