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>
<script>
  var test = [ "href", "src", "width", "height" ];
</script>
      
<script>
Benchmark.prototype.setup = function() {
  var obj = {};

};
</script>

Preparation code output

<script> var test = [ "href", "src", "width", "height" ]; </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
jQuery.each Method
jQuery.each(test, function(k, v){
  obj[v] = jQuery.fn[v];
});
pending…
for() Method
for(var i=0, j=test.length; i<j; i++) {
  obj[test[i]] = jQuery.fn[test[i]];
}
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