jQuery.each vs for..in

JavaScript performance comparison

Test case created by David Rodrigues

Preparation code

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
  var test = [ "href", "src", "width", "height" ];
Benchmark.prototype.setup = function() {
  var obj = {};


Preparation code output

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
jQuery.each Method
jQuery.each(test, function(k, v){
  obj[v] = jQuery.fn[v];
for() Method
for(var i=0, j=test.length; i<j; i++) {
  obj[test[i]] = jQuery.fn[test[i]];

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

Compare results of other browsers