$(this).attr('id') VS this.id

Benchmark created by Superficial on


Description

Show the speed difference between using $(this).attr('id') and this.id

Preparation HTML

<ul id="thisOne">
    <li></li>
    <li id="li1"></li>
    <li></li>
    <li id="li2"></li>
    <li></li>
    <li id="li3"></li>
    <li></li>
    <li id="li4"></li>
    <li></li>
    <li id="li5"></li>
    <li></li>
    <li id="li6"></li>
</ul>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>

Test runner

Ready to run.

Testing in
TestOps/sec
$(this).attr('id');
$('#thisOne > li').each(function() {
 var x = $(this).attr('id');
});
ready
this.id;
$('#thisOne > li').each(function() {
 var x = this.id;
});
ready

Revisions

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

  • Revision 1: published by Superficial on