document.all vs document.getElementsByTagName

JavaScript performance comparison

Test case created by Daniel15

Info

Speed test for getting all elements on the page

Preparation code

<div class="test1"></div>
<div class="test2"></div>
<div class="test3"></div>
<div class="test4"></div>
<div class="test5"></div>
<div class="test6"></div>
<div class="test7"></div>
<div class="test8"></div>
<div class="test9">
        <div class="test10"></div>
        <div class="test11"></div>
        <div class="test12"></div>
        <div class="test13"></div>
        <div class="test14"></div>
        <div class="test15"></div>
        <div class="test16"></div>
</div>

Preparation code output

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
document.all
var els = document.all;
var test = els[0].nodeName;
pending…
document.getElementsByTagName
var els = document.getElementsByTagName('*');
var test = els[0].nodeName;
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