jquery each vs. map

JavaScript performance comparison

Test case created

Preparation code

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
<script>
Benchmark.prototype.setup = function() {
    var allStarCast = [{
      firstName: "Zack",
      lastName: "Morris"
    }, {
      firstName: "Kelly",
      lastName: "Kapowski"
    }, {
      firstName: "Lisa",
      lastName: "Turtle"
    }, {
      firstName: "Screech",
      lastName: "Powers"
    }, {
      firstName: "A.C.",
      lastName: "Slater"
    }, {
      firstName: "Jessie",
      lastName: "Spano"
    }, {
      firstName: "Richard",
      lastName: "Belding"
    }];
};
</script>

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
$.each
// $.each, iterate through the cast and find zack and kelly
var worldsCutestCouple = [];
$.each(allStarCast, function(idx, actor) {
  if (actor.firstName === "Zack" || actor.firstName === "Kelly") {
    worldsCutestCouple.push(actor);
  }
});
pending…
$.map
// $.map, iterate through the cast and find zack and kelly
var worldsCutestCouple = $.map(allStarCast, function(actor, idx) {
  if (actor.firstName === "Zack" || actor.firstName === "Kelly") {
    return actor;
  }
});
pending…
$.grep
var worldsCutestCouple = $.grep(allStarCast, function(actor) {
  return (actor.firstName === "Zack" || actor.firstName === "Kelly");
});
 
pending…

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

Compare results of other browsers

0 comments

Add a comment