Caching DOM References

JavaScript performance comparison

Test case created by Jon Raasch

Preparation code

<div id="my-element"></div>
    

Preparation code output

<div id="my-element"></div>

Test runner

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

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
Not Cached
for ( var i = 0; i < 10; i++ ) {
     var myEl = document.getElementById('my-element');

    // whatever you want to do with myEl
}
pending…
Cached
var myEl = document.getElementById('my-element');

for ( var i = 0; i < 10; i++ ) {
    // whatever you want to do with myEl
}
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.

0 Comments