Array.forEach vs for loop vs while loop vs lodash

JavaScript performance comparison

Revision 492 of this test case created by Artem Churyukin

Preparation code

<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/2.4.1/lodash.min.js"></script>
      
<script>
Benchmark.prototype.setup = function() {
  // Initialize the base array
  var arr = [];
  for (var i = 0; i < 500; i++) {
    arr[i] = i;
  }
  var len = arr.length;
  
  // The function to be called on each iteration
  var iterateFunc = function(item, index) {
    return index + item * 3 * 8;
  };

};
</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
Array.forEach Arrow
arr.forEach(iterateArrowFunc);
pending…

Revisions

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

0 Comments