caching getelementbyid

JavaScript performance comparison

Test case created

Preparation code

<div id="foo">
<p>Lorem Ipsum</p>
</div>
<script>
Benchmark.prototype.setup = function() {
    var cachedSelector = document.getElementById("foo");
    var elid = document.getElementById;
};
</script>

Preparation code output

Lorem Ipsum

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
caching getElementById
for (var i = 0; i < 10; i++){
cachedSelector.style = "display: none;"}
pending…
not caching getElementById
for (var i = 0; i < 10; i++){
document.getElementById("foo").style = "display: none;"}
pending…

You can edit these tests or add even more tests to this page by appending /edit to the URL.

Compare results of other browsers

0 comments

Add a comment