Run details:
Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36
Chrome 70
Windows 7
Desktop
5 years ago
Test name Executions per second
var child = JSON.parse(JSON.stringify(parent)); 82126.1 Ops/sec
var child = []; for (var i = 0; i < parent.length; i++) { child[i] = parent[i].slice(); } 255697.4 Ops/sec
+= 1: var child = []; for (var i = 0; i < parent.length; i += 1) { child[i] = parent[i].slice(); } 263973.4 Ops/sec
Script Preparation code:
Tests:
  • var child = JSON.parse(JSON.stringify(parent));

  • child[i] = parent[i].slice()/// var child = []; for (var i = 0; i < parent.length; i += 1) { child[i] = parent[i].slice(); }

  • child[i][j] = parent[i][j]/// var child = []; for (var i = 0; i < parent.length; i += 1) { child[i] = []; for (var j = 0; j < parent[i].length; j += 1) { child[i][j] = parent[i][j]; } }

  • var child = JSON.parse(JSON.stringify(sparent));

  • var child = sparent.slice();

  • child[i] = sparent[i]/// var child = []; for (var i = 0; i < parent.length; i += 1) { child[i] = sparent[i]; }


;