getElementById Cache (v2)

Revision 2 of this benchmark created on


Description

getElementByIdの結果をキャッシュした場合の比較 http://d.hatena.ne.jp/namusyaka/20110304/1299228350 の計測データが一部おかしい感じがする。

Preparation HTML

<div id="test"></div>

<script>
  var cache = {},
      _d = document;
  
  function $(id) {
   return cache[id] || (cache[id] = _d.getElementById(id))
  }
  
  function _$(id) {
   return _d.getElementById(id)
  }
  
  function qsa(id) {
   return _d.querySelectorAll('#' + id)[0];
  }
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
TEST1
_d.getElementById('test');
ready
Test 2
$('test');
ready
Test 3
_$('test');
ready
Test4
qsa('test');
ready

Revisions

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