title: Why is a custom array reverse implementation twice as fast versus .reverse() in V8
body: <p>A simple implementation for reversing an array is twice as fast compared to the built in function in Javascript, when tested in Chrome. What's V8 doing? Here is the test:</p>
  
  <pre><code>var newArr = [];
  var newArrDefault = [];
  for(var i = 0; i &lt; 10000000; i++){
      newArr[i] = i;
      newArrDefault[i] = i;
  }
  
  
  var startDefault = new Date();
  newArrDefault.reverse();
  console.log("Built in method took " + (new Date().getTime() - startDefault.getTime()));
  
  
  var start = new Date();
  for(var i = 0; i &lt; newArr.length / 2; i++){
      var tmp = newArr[i];
      newArr[i] = newArr[newArr.length-i-1];
      newArr[newArr.length-i-1] = tmp;
  }
  console.log("Custom method took " + (new Date().getTime() - start.getTime()));
  </code></pre>
  
  <p>Results on Version 20.0.1132.47 Ubuntu 12.04 (144678):</p>
  
  <pre><code>Built in method took 149
  Custom method took 71
  </code></pre>