Script Preparation code:
AخA
 
var array = [{x: 1, copy: true}, {y: 2, copy: false}, {z: 3, copy: true}, {u: 0, copy: true}, {v: -1, copy: true}, {w: -2, copy: false}];
var copy = array.map(item => Object.assign(item, {copy: false}));
Tests:
  • slice

     
    copy = array.slice(0);
  • for loop

     
    for (let i = 0; i < array.length; i++) {
      if (array[i].copy) {
        copy[i] = array[i];
      }
    }
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    slice
    for loop

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 3 years ago)
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36
Chrome 96 on Mac OS X 10.15.7
View result in a separate tab
Test name Executions per second
slice 6365398.0 Ops/sec
for loop 1242282.9 Ops/sec