Using getElementsByTagName vs children

JavaScript performance comparison

Revision 2 of this test case created

Info

Which is faster?

Preparation code

<script src="//code.jquery.com/jquery-latest.min.js"></script>
<ul id="list">
  <li>Placeholder text</li>
  <li>Placeholder text</li>
  <li>Placeholder text</li>
  <li>Placeholder text</li>
  <li>Placeholder text</li>
  <li>Placeholder text</li>
  <li>Placeholder text</li>
  <li>Placeholder text</li>
  <li>Placeholder text</li>
  <li>Placeholder text</li>
  <li>Placeholder text</li>
  <li>Placeholder text</li>
  <li>Placeholder text</li>
  <li>Placeholder text</li>
  <li>Placeholder text</li>
  <li>Placeholder text</li>
  <li>Placeholder text</li>
  <li>Placeholder text</li>
  <li>Placeholder text</li>
  <li>Placeholder text</li>
  <li>Placeholder text</li>
  <li>Placeholder text</li>
  <li>Placeholder text</li>
  <li>Placeholder text</li>
  <li>Placeholder text</li>
  <li>Placeholder text</li>
  <li>Placeholder text</li>
  <li>Placeholder text</li>
  <li>Placeholder text</li>
  <li>Placeholder text</li>
  <li>Placeholder text</li>
  <li>Placeholder text</li>
  <li>Placeholder text</li>
  <li>Placeholder text</li>
  <li>Placeholder text</li>
  <li>Placeholder text</li>
  <li>Placeholder text</li>
  <li>Placeholder text</li>
  <li>Placeholder text</li>
  <li>Placeholder text</li>
  <li>Placeholder text</li>
  <li>Placeholder text</li>
  <li>Placeholder text</li>
  <li>Placeholder text</li>
  <li>Placeholder text</li>
  <li>Placeholder text</li>
  <li>Placeholder text</li>
  <li>Placeholder text</li>
  <li>Placeholder text</li>
  <li>Placeholder text</li>
  <li>Placeholder text</li>
  <li>Placeholder text</li>
  <li>Placeholder text</li>
  <li>Placeholder text</li>
  <li>Placeholder text</li>
  <li>Placeholder text</li>
  <li>Placeholder text</li>
  <li>Placeholder text</li>
  <li>Placeholder text</li>
  <li>Placeholder text</li>
  <li>Placeholder text</li>
  <li>Placeholder text</li>
  <li>Placeholder text</li>
  <li>Placeholder text</li>
  <li>Placeholder text</li>
  <li>Placeholder text</li>
  <li>Placeholder text</li>
  <li>Placeholder text</li>
  <li>Placeholder text</li>
  <li>Placeholder text</li>
  <li>Placeholder text</li>
  <li>Placeholder text</li>
  <li>Placeholder text</li>
  <li>Placeholder text</li>
  <li>Placeholder text</li>
  <li>Placeholder text</li>
  <li>Placeholder text</li>
  <li>Placeholder text</li>
  <li>Placeholder text</li>
  <li>Placeholder text</li>
  <li>Placeholder text</li>
  <li>Placeholder text</li>
  <li>Placeholder text</li>
  <li>Placeholder text</li>
  <li>Placeholder text</li>
  <li>Placeholder text</li>
  <li>Placeholder text</li>
  <li>Placeholder text</li>
  <li>Placeholder text</li>
  <li>Placeholder text</li>
  <li>Placeholder text</li>
  <li>Placeholder text</li>
  <li>Placeholder text</li>
  <li>Placeholder text</li>
  <li>Placeholder text</li>
  <li>Placeholder text</li>
  <li>Placeholder text</li>
  <li>Placeholder text</li>
  <li>Placeholder text</li>
  <li>Placeholder text</li>
</ul>

Preparation code output

  • Placeholder text
  • Placeholder text
  • Placeholder text
  • Placeholder text
  • Placeholder text
  • Placeholder text
  • Placeholder text
  • Placeholder text
  • Placeholder text
  • Placeholder text
  • Placeholder text
  • Placeholder text
  • Placeholder text
  • Placeholder text
  • Placeholder text
  • Placeholder text
  • Placeholder text
  • Placeholder text
  • Placeholder text
  • Placeholder text
  • Placeholder text
  • Placeholder text
  • Placeholder text
  • Placeholder text
  • Placeholder text
  • Placeholder text
  • Placeholder text
  • Placeholder text
  • Placeholder text
  • Placeholder text
  • Placeholder text
  • Placeholder text
  • Placeholder text
  • Placeholder text
  • Placeholder text
  • Placeholder text
  • Placeholder text
  • Placeholder text
  • Placeholder text
  • Placeholder text
  • Placeholder text
  • Placeholder text
  • Placeholder text
  • Placeholder text
  • Placeholder text
  • Placeholder text
  • Placeholder text
  • Placeholder text
  • Placeholder text
  • Placeholder text
  • Placeholder text
  • Placeholder text
  • Placeholder text
  • Placeholder text
  • Placeholder text
  • Placeholder text
  • Placeholder text
  • Placeholder text
  • Placeholder text
  • Placeholder text
  • Placeholder text
  • Placeholder text
  • Placeholder text
  • Placeholder text
  • Placeholder text
  • Placeholder text
  • Placeholder text
  • Placeholder text
  • Placeholder text
  • Placeholder text
  • Placeholder text
  • Placeholder text
  • Placeholder text
  • Placeholder text
  • Placeholder text
  • Placeholder text
  • Placeholder text
  • Placeholder text
  • Placeholder text
  • Placeholder text
  • Placeholder text
  • Placeholder text
  • Placeholder text
  • Placeholder text
  • Placeholder text
  • Placeholder text
  • Placeholder text
  • Placeholder text
  • Placeholder text
  • Placeholder text
  • Placeholder text
  • Placeholder text
  • Placeholder text
  • Placeholder text
  • Placeholder text
  • Placeholder text
  • Placeholder text
  • Placeholder text
  • Placeholder text
  • Placeholder text

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 & getElementsByTagName
document.getElementById('list').getElementsByTagName('li');
pending…
$({ID}) & getElementsByTagName
$('#list').get(0).getElementsByTagName('li');
pending…
children w/ filter
$('#list').children('li');
pending…
children w/out filter
$('#list').children();
pending…
find
$('#list').find('li');
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