caching getelementbyid

JavaScript performance comparison

Test case created

Preparation code

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

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++){ = "display: none;"}
not caching getElementById
for (var i = 0; i < 10; i++){
document.getElementById("foo").style = "display: none;"}

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

Compare results of other browsers


Comment form temporarily disabled.

Add a comment