Testing methods to store data about dome elements

Benchmark created on


Preparation HTML

<script src="http://code.jquery.com/jquery-1.5.js"></script>

<div id="target" class="target"></div>
<script>
  target = $("#target")
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Testing using class
for (var i = 0; i < 101; i++) {
 if (!target.hasClass("foo")) {
  target.attr("class", "target foo");
 }
}
ready
Testing using $.data
for (var i = 0; i < 101; i++) {
 if ($.data(target.get(0), "status", "foo")) {
  target.attr("class", "target foo");
  $.data(target, "status", "foo");
 }
}
ready

Revisions

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