caching global a var ?

Benchmark created by Jonas Fischer on


Preparation HTML

<script>
  var a = Array({
   test: "fdslfsfdfsd",
   resize: 2
  }, function() {
   return Math.random() * 3465;
  }, function(v) {
   return "sdfksdjf" + v;
  }, function() {
   return document.title + "<-";
  }, "fdslfsfdfsd", "2.43.2", "This is the desc. of the object. ... Some text ... .", "abcde", 3, (Math.random() * 434) | 0, String.fromCharCode((Math.random() * 255) | 0, (Math.random() * 255) | 0), function() {
   var s = a[0].test;
   var s = a[1]();
   var s = a[2](a[10]);
   var s = a[3]();
   var s = a[4];
   var s = a[5];
   var s = a[6];
   a[6] = s + "";
   var s = a[7];
   var s = a[8];
   var s = a[9];
   a[9] = (Math.random() * 434) | 0;
   var s = a[10];
   a[10] = String.fromCharCode((Math.random() * 255) | 0, (Math.random() * 255) | 0);
  }, function() {
   var t = a;
   var s = t[0].test;
   var s = t[1]();
   var s = t[2](t[10]);
   var s = t[3]();
   var s = t[4];
   var s = t[5];
   var s = t[6];
   t[6] = s + "";
   var s = t[7];
   var s = t[8];
   var s = t[9];
   t[9] = (Math.random() * 434) | 0;
   var s = t[10];
   t[10] = String.fromCharCode((Math.random() * 255) | 0, (Math.random() * 255) | 0);
  }, function() {
   var s = this[0].test;
   var s = this[1]();
   var s = this[2](this[10]);
   var s = this[3]();
   var s = this[4];
   var s = this[5];
   var s = this[6];
   this[6] = s + "";
   var s = this[7];
   var s = this[8];
   var s = this[9];
   this[9] = (Math.random() * 434) | 0;
   var s = this[10];
   this[10] = String.fromCharCode((Math.random() * 255) | 0, (Math.random() * 255) | 0);
  });
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Do not cache
var i = 0;
while (i++ != 50) a[11]();
ready
cache with the global var with a local var named t
var i = 0;
while (i++ != 50) a[12]();
ready
use this ( in some cases, be carefull with this )
var i = 0;
while (i++ != 50) a[13]();
ready

Revisions

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

  • Revision 1: published by Jonas Fischer on