Cache vs. Closure

JavaScript performance comparison

Revision 2 of this test case created by Matt

Preparation code

<meta name="A" content="1" />
<meta name="B" content="2" />
<meta name="C" content="3" />
<meta name="D" content="4" />
<meta name="E" content="5" />
<script>
  var metaTags = document.getElementsByTagName("meta");
  
  function getMetaTags(x) {
   var metaTags = document.getElementsByTagName("meta");
   return function(y) {
    return metaTags[y];
   };
  }
  
  getMetaTags(); // we have to run this to equalize the tests.
</script>
    

Preparation code output

<meta name="A" content="1" /> <meta name="B" content="2" /> <meta name="C" content="3" /> <meta name="D" content="4" /> <meta name="E" content="5" />

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
Caching
metaTags["A"];
metaTags["B"];
metaTags["C"];
metaTags["D"];
metaTags["E"];
pending…
Closure
var gmtFn = getMetaTags();

gmtFn("A");
gmtFn("B");
gmtFn("C");
gmtFn("D");
gmtFn("E");
pending…

Compare results of other browsers

Revisions

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

0 Comments