CoffeeScript's for vs. Underscore _.each vs. jQuery $.each

JavaScript performance comparison

Revision 14 of this test case created

Info

Compare for loop performance.

Preparation code

<script src="//underscorejs.org/underscore-min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script>
Benchmark.prototype.setup = function() {
    var _i, _results;
   
    window.array = (function() {
      _results = [];
      for (_i = 1; _i <= 1000; _i++){ _results.push(_i); }
      return _results;
    }).apply(this);
};
</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
CoffeeScript for loop
var string = "";
string += item.toString() for item in array
 
pending…
_.each
var string = "";

_.each(array, function(item) {
  return string += item.toString();
});
pending…
$.each
var string = "";

$.each(array, function() {
  return string += this.toString();
});
pending…
array.forEach
var string = "";

array.forEach(function(item) {
  return string += item.toString();
});
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