document.getElementById vs bound byId

JavaScript performance comparison

Test case created by Geek#

Preparation code

<input type="text" id="testInput" />
<script>
var byId = document.getElementById.bind(document);
var closure = (function() {
  var doc = document,
    getElement = doc.getElementById;
  return function(id) {
    return getElement.call(doc, id);
  };
})();
var callById = document.getElementById;
function simple(id)
{
return document.getElementById(id);
}
</script>
    

Preparation code output

<input type="text" id="testInput" />

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
document.getElementById
document.getElementById("testInput");
pending…
byId
byId("testInput");
pending…
closure
closure("testInput")
pending…
call
callById.call(document, "testInput");
pending…
simple
simple("testInput");
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