Global vs Local valiable access

Benchmark created by azproduction on


Preparation HTML

<script>
  var a = [1,2,3,4,5,6,7,8,9,10,1,2,3,4,5,6,7,8,9,10,1,2,3,4,5,6,7,8,9,10,1,2,3,4,5,6,7,8,9,10,1,2,3,4,5,6,7,8,9,10],
      dt,
      index,
      i,
      c,
      r,
      t,
      res
      ;
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Activation object Arguments scope
(function (a, dt, index, i, c, r, t, res) {
r = [];
c = a.length;
 
index = 10000;
while (index--) {
   for (i = 0, res = []; i < c; i++) {
       t = a[i];
       if (t >= 2.236067) {
           continue;
       } else {
           res.push(t * t);
       }
   }
}
 
}([1,2,3,4,5,6,7,8,9,10,1,2,3,4,5,6,7,8,9,10,1,2,3,4,5,6,7,8,9,10,1,2,3,4,5,6,7,8,9,10,1,2,3,4,5,6,7,8,9,10]));
ready
Activation object scope
(function () {
var a = [1,2,3,4,5,6,7,8,9,10,1,2,3,4,5,6,7,8,9,10,1,2,3,4,5,6,7,8,9,10,1,2,3,4,5,6,7,8,9,10,1,2,3,4,5,6,7,8,9,10],
    dt,
    index,
    i,
    c,
    r,
    t,
    res
    ;
 
r = [];
c = a.length;

index = 10000;
while (index--) {
   for (i = 0, res = []; i < c; i++) {
       t = a[i];
       if (t >= 2.236067) {
           continue;
       } else {
           res.push(t * t);
       }
   }
}
 
}());
ready
Global scope
r = [];
c = a.length;

index = 10000;
while (index--) {
   for (i = 0, res = []; i < c; i++) {
       t = a[i];
       if (t >= 2.236067) {
           continue;
       } else {
           res.push(t * t);
       }
   }
}
ready

Revisions

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

  • Revision 1: published by azproduction on