Attr vs Direct DOM Access

Benchmark created on


Preparation HTML

<ul>
<li>item 1</li>
<li>item 2</li>
<li>item 3</li>
<li>item 4</li>
<li>item 5</li>
</ul>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>

Test runner

Ready to run.

Testing in
TestOps/sec
Attr
$("ul > li").each(function() {
 var value = $(this).attr("class");
 value.replace("cat-item-", "");
 $(this).attr("class", value);
});
ready
Direct
$("ul > li").each(function() {
 this.className = this.className.replace('cat-item', '');
});
ready

Revisions

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