getElementById VS jQuery('#id')

JavaScript performance comparison

Revision 62 of this test case created

Preparation code

<script src="http://code.jquery.com/jquery-1.8.3.min.js">
</script>
<p id="foo">
  Test
  <div class="inner">
    inner
  </div>
</p>

Preparation code output

Test

inner

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
getElementById
document.getElementById('foo');
pending…
jQuery
$('#foo');
pending…
jQuery wrapped getElementById
$(document.getElementById('foo'));
pending…
Process dom node
$(document.getElementById('foo')).html(Math.random()*999999);
pending…
Process jquery node
$('#foo').html(Math.random()*999999);
pending…
Find elements in dom node
$('.inner');
pending…
Find elements in jquery node
document.getElementsByClassName('inner');
pending…
$(document.getElementsByClassName('inner'))
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

0 comments

Add a comment