const vs var in closures (v6)

Revision 6 of this benchmark created on


Setup

funcs = [];
    funcOrObjs = [];
    count = 10000;
    var getter = function (x) { return function () { return x; }; };
    for (var i = 0; i < count; i++) {
      funcs.push(getter({num: i}));
      if (i % 2 === 0) funcOrObjs.push(i); else funcOrObjs.push(getter({num: i}));
    }
    result=[];

Test runner

Ready to run.

Testing in
TestOps/sec
const
for (var i = 0; i < count; i++) {
  result.push(funcs[i]());
}
ready
var
for (var i = 0; i < count; i++) {
  var a = funcOrObjs[i];
  if (typeof a === 'function') a = a();
  result.push(a);
}
ready
global const
for (var i = 0; i < count; i++) {
  result.push(funcs[i]());
}
ready
global var
for (var i = 0; i < count; i++) {
  var a = funcOrObjs[i];
  if (typeof a === 'function') a = a();
  result.push(a);
}
ready

Revisions

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