attr vs attrhooks

JavaScript performance comparison

Test case created by timmywil and last updated

Preparation code

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.js"></script>
<script>
var oldAttr = jQuery.noConflict();
</script>
<script src="http://code.jquery.com/jquery-1.6.js"></script>
<script>
var newAttr = jQuery.noConflict();
</script>
<div id="testDiv"></div>
<input type="text" id="someInput" value="foo">
<script>
  var oldDiv = oldAttr('#testDiv'),
      oldInput = oldAttr('#someInput'),
      newDiv = newAttr('#testDiv'),
      newInput = newAttr('#someInput');
</script>
    

Preparation code output

<script> var oldAttr = jQuery.noConflict(); </script> <script src="http://code.jquery.com/jquery-1.6.js"></script> <script> var newAttr = jQuery.noConflict(); </script> <div id="testDiv"></div> <input type="text" id="someInput" value="foo"> <script> var oldDiv = oldAttr('#testDiv'), oldInput = oldAttr('#someInput'), newDiv = newAttr('#testDiv'), newInput = newAttr('#someInput'); </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
oldDiv.attr('id')
oldDiv.attr('id');
pending…
newDiv.attr('id')
newDiv.attr('id');
pending…
oldInput.attr('value')
oldInput.attr('value');
pending…
newInput.attr('value')
newInput.attr('value');
pending…
oldDiv.attr('class', 'wowzers')
oldDiv.attr('class', 'wowzers');
pending…
newDiv.attr('class', 'wowzers')
newDiv.attr('class', 'wowzers');
pending…
oldInput.attr('foo', 'bar')
oldInput.attr('foo', 'bar');
pending…
newInput.attr('foo', 'bar')
newInput.attr('foo', 'bar');
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.

4 Comments

Wendal commented :

It seem good!!

Haydur commented :

Without standardized hardware, these rsults are skewed at best. Of course Safari will score better in most tests, it ships with some of today's fastest desktops and laptops. Do you really expect Chrome 12 on a PC with E5700 and DDR2 to be as fast as Safari on E7600 and DDR3?

Rangoric commented :

This isn't to compare across browsers really (You can run the tests on your machine in the range of browsers you care about) it is more within that browser which version is faster.