closed-vars-vs-property

Benchmark created by hue on


Setup

function addFunc() {
      addFunc.value++;
    }
    addFunc.value = 0;
    
    var addProp = function() {
      addProp.value++;
    };
    addProp.value = 0;
    
    var addClosure = (function() {
      var value = 0;
    
      function f() {
        value++;
      }
    
      f.getValue = function() {
        return value;
      };
    
      return f;
    })();

Teardown


    console.log(addFunc.value);
    console.log(addProp.value);
    console.log(addClosure.getValue());
  

Test runner

Ready to run.

Testing in
TestOps/sec
1
addFunc();
ready
2
addProp();
ready
3
addClosure();
ready

Revisions

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