ES5 Array methods

JavaScript performance comparison

Revision 2 of this test case created

Info

Testing various array method implementations.

Lo-Dash should perform the best because it implements simplified alternatives. Lo-Dash also manages to pack in extra functionality. (e.g. lodash.forEach can be chainable because it returns the array, and can exit early if callback returns false)

Preparation code

<script src="//dl.dropbox.com/u/513327/lodash.js"></script>
<script>
var lodash = _.noConflict();
</script>
<script src="//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.4.2/underscore-min.js"></script>
<script>
Benchmark.prototype.setup = function() {
    var array = Array(100);
    for (var index = 0; index < 100; index++) {
      array[index] = index;
    }
};
</script>

Preparation code output

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
Array#forEach
var result = Array(100);
array.forEach(function(value, index) {
  result[index] = value * value;
});
pending…
_.forEach
var result = Array(100);
_.forEach(array, function(value, index) {
  result[index] = value * value;
});
pending…
lodash.forEach
var result = Array(100);
lodash.forEach(array, function(value, index) {
  result[index] = value * value;
});
pending…
Array#map
var result = array.map(function(value) {
  return value * value;
});
pending…
_.map
var result = _.map(array, function(value) {
  return value * value;
});
pending…
lodash.map
var result = lodash.map(array, function(value) {
  return value * value;
});
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

0 comments

Add a comment