Cache array

JavaScript performance comparison

Test case created

Preparation code

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<div id="container1"></div>
<div id="container2"></div>
<div id="container3"></div>
<div id="container4"></div>
<div id="container5"></div>
<div id="container6"></div>
<div id="container7"></div>
<div id="container8"></div>
<div id="container9"></div>
<div id="container10"></div>
<div id="container11"></div>
<div id="container12"></div>
<div id="container13"></div>
<div id="container14"></div>
<div id="container15"></div>
<div id="container16"></div>
<div id="container17"></div>
<div id="container18"></div>
<div id="container19"></div>
<div id="container20"></div>
<div id="container21"></div>
<div id="container22"></div>
<div id="container23"></div>
<div id="container24"></div>
<div id="container25"></div>
<div id="container26"></div>
<div id="container27"></div>
<div id="container28"></div>
<div id="container29"></div>
<div id="container30"></div>
<div id="container31"></div>
<div id="container32"></div>
<div id="container33"></div>
<div id="container34"></div>
<div id="container35"></div>
<div id="container36"></div>
<div id="container37"></div>
<div id="container38"></div>
<div id="container39"></div>
<div id="container40"></div>
<div id="container41"></div>
<div id="container42"></div>
<div id="container43"></div>
<div id="container44"></div>
<div id="container45"></div>
<div id="container46"></div>
<div id="container47"></div>
<div id="container48"></div>
<div id="container49"></div>
<div id="container50"></div>
<div id="container51"></div>
<div id="container52"></div>
<div id="container53"></div>
<div id="container54"></div>
<div id="container55"></div>
<div id="container56"></div>
<div id="container57"></div>
<div id="container58"></div>
<div id="container59></div>
<div id="container60"></div>
<div id="container61"></div>
<div id="container62"></div>
<div id="container63"></div>
<div id="container64"></div>
<div id="container65"></div>
<div id="container66"></div>
<div id="container67"></div>
<div id="container68"></div>
<div id="container69"></div>
<div id="container70"></div>
<div id="container71"></div>
<div id="container72"></div>
<div id="container73"></div>
<div id="container74"></div>
<div id="container75"></div>
<div id="container76"></div>
<div id="container77"></div>
<div id="container78"></div>
<div id="container79"></div>
<div id="container80"></div>
<div id="container81"></div>
<div id="container82"></div>
<div id="container83"></div>
<div id="container84"></div>
<div id="container85"></div>
<div id="container86"></div>
<script>
Benchmark.prototype.setup = function() {
    var cachearray = {};
    cachearray['cont1'] = document.getElementById('container1');
    cachearray['cont2'] = document.getElementById('container2');
    cachearray['cont45'] = document.getElementById('container45');
    cachearray['cont46'] = document.getElementById('container46');
    cachearray['cont48'] = document.getElementById('container48');
    cachearray['cont56'] = document.getElementById('container56');
    cachearray['cont71'] = document.getElementById('container71');
    cachearray['cont72'] = document.getElementById('container72');
    cachearray['cont81'] = document.getElementById('container81');
   
    var cont1 = document.getElementById('container1'),
    cont2 = document.getElementById('container2'),
    cont45 = document.getElementById('container45'),
    cont46 = document.getElementById('container46'),
    cont48 = document.getElementById('container48'),
    cont56 = document.getElementById('container56'),
    cont71 = document.getElementById('container71'),
    cont72 = document.getElementById('container72'),
    cont81 = document.getElementById('container81');
};
</script>

Preparation code output

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
cache array
cachearray['cont1'].innerHTML = "test";
cachearray['cont2'].innerHTML = "test";
cachearray['cont45'].innerHTML = "test";
cachearray['cont46'].innerHTML = "test";
cachearray['cont48'].innerHTML = "test";
cachearray['cont56'].innerHTML = "test";
cachearray['cont71'].innerHTML = "test";
cachearray['cont72'].innerHTML = "test";
cachearray['cont81'].innerHTML = "test";
pending…
cache vars
cont1.innerHTML = "test";
cont2.innerHTML = "test";
cont45.innerHTML = "test";
cont46.innerHTML = "test";
cont48.innerHTML = "test";
cont56.innerHTML = "test";
cont71.innerHTML = "test";
cont72.innerHTML = "test";
cont81.innerHTML = "test";
pending…
cache array for
for(var i = 0, len = cachearray.length; i < len; i++)
{
cachearray[i].innerHTML = "test";
}
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

Add a comment