document.all vs document.getElementsByTagName

JavaScript performance comparison

Revision 3 of this test case created

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>
<script>
Benchmark.prototype.setup = function() {
    var doc = window.document;
};
</script>

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
doc.all;
pending…
document.getElementsByTagName
doc.getElementsByTagName('*');
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