Array fill vs loop

JavaScript performance comparison

Test case created by CyberAP

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  const length = 1000

};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
Fill
new Array(length).fill(0)
pending…
classic for
const arr = new Array(length)
for (var i = 0; i < length; i++) arr[i] = 0
pending…
for with increment in body
const arr = new Array(length)
for (var i = 0; i < length;) arr[i++] = 0
pending…
while
const arr = new Array(length)
let i = length
while (i) arr[--i] = 0
pending…
while with assignment in condition
const arr = new Array(length)
let i = length
while (arr[i--] = 0, i);
pending…

Compare results of other browsers

Revisions

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

0 Comments