Slice vs for loops

Benchmark created by dellsystem on


Setup

var array = [];
    
    for (var i = 0; i < 10000; i++) {
      array[i] = 100;
    }

Test runner

Ready to run.

Testing in
TestOps/sec
Slice
var array2 = array.slice(0, array.length)
ready
For loop
var array2 = [];

for (var j = 0, length = array.length; j < length; j++) {
  array2[j] = array[j];
}
ready

Revisions

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

  • Revision 1: published by dellsystem on