getElementById VS jQuery('#id') (v204)

Revision 204 of this benchmark created on


Preparation HTML

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js">
</script>
<p id="b1"></p>
<p id="b2"></p>
<p id="b3"></p>
<p id="b4"></p>
<p id="b5"></p>
<p id="b6"></p>
<p id="b7"></p>
<p id="b8"></p>
<p id="b9"></p>
<p id="b10"></p>
<p id="b11"></p>
<p id="b12"></p>
<p id="b13"></p>
<p id="b14"></p>
<p id="b15"></p>
<p id="b16"></p>
<p id="b17"></p>
<p id="b18"></p>
<p id="b19"></p>
<p id="b20"></p>
<table id="foo"><tr><td>
  Test
</td></tr></table>

<p id="bar">
  bars</p>
<script>
var el = document.getElementById("foo");
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
getElementById
var a=$(document.getElementById('foo')).rows[0].cells[0];
ready
jQuery Selector
var a=$('#foo').rows[0].cells[0];
ready
Custom Method
var a=el.rows[0].cells[0];
ready
$ Custom Method
var a=1;
ready
jQuery Window Object
$('#foo');
$('#bar');
ready
realgetelementbyid
document.getElementById('foo').rows[0].cells[0];
ready
typeof
if(typeof (document.getElementById('foo')) === "undefined"){}
ready

Revisions

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