attr vs attrhooks

JavaScript performance comparison

Revision 2 of this test case created by timmywil

Info

Compares the performance of attrhooks vs the old attr

Preparation code

<script src="//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-git.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

Test runner

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

Java applet disabled.

Testing in unknown unknown
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. Here’s a list of current revisions for this page:

0 comments

Add a comment