jQuery attr() vs. Native setAttribute() (v11)

Revision 11 of this benchmark created on


Description

jQuery's attr() method will always have more overhead because of the extensibility added.

Preparation HTML

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6/jquery.min.js"></script><input type="text" id="btn"></div>

Test runner

Ready to run.

Testing in
TestOps/sec
1
//$("#btn").attr("disabled", "disabled");

$("#btn").attr({
  "x": 100 / 2,
  "y": 100 / 2,
  "width": 100,
  "height": 100,
  "cx": 1,
  "cy": 1,
  "net": 1,
  "pin": 1,
  "number": 1
});
ready
2
//document.getElementById('btn').setAttribute("disabled", "disabled");

$("#btn").attr("x", 100 / 2)
  .attr("y", 100 / 2)
  .attr("width", 100)
  .attr("height", 100)
  .attr("cx", 1)
  .attr("cy", 1)
  .attr("net", 1)
  .attr("pin", 1)
  .attr("number", 1)
ready
3
//document.getElementById('btn').setAttribute("disabled", "disabled");

document.getElementById('btn').setAttribute("x", 100 / 2);
  .setAttribute("y", 100 / 2)
  .setAttribute("width", 100)
  .setAttribute("height", 100)
  .setAttribute("cx", 1)
  .setAttribute("cy", 1)
  .setAttribute("net", 1)
  .setAttribute("pin", 1)
  .setAttribute("number", 1)
ready

Revisions

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