document.getElementById() (v2)

Revision 2 of this benchmark created by gf3 on


Preparation HTML

<p id="foo">This is an element with <code>id="foo"</code>.</p>
<script>
  function gEBI(id) {
   return document.getElementById(id);
  };
  
  var $nodes = {}; // will be used by $memo()
  
  function $memo(id) {
   return $nodes[id] ? $nodes[id] : $nodes[id] = document.getElementById(id);
  };
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
document.getElementById()
var node = document.getElementById('foo');
ready
gEBI()
var node = gEBI('foo');
ready
Memoized $memo()
var node = $memo('foo');
ready
document.querySelector()
var node = document.querySelector('#foo');
ready

Revisions

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