Closure vs function prop

Benchmark created by SGO on


Setup

function O(a, b) {
      this.a = a;
      this.b = b;
    }
    
    O.prototype.foo1 = function foo1() {
      return this.a + this.b + foo1.c
    };
    O.prototype.foo1.c = 3;
    
    O.prototype.foo2 = function() {
      var c = 3;
      return function() {
        this.a + this.b + c
      }
    }();
    
    var t = [];
    for (var i = 0; i < 100; i++) t[i] = new O(Math.floor(Math.random() * 100), Math.floor(Math.random() * 100));

Test runner

Ready to run.

Testing in
TestOps/sec
function prop
t[Math.floor(Math.random() * 100)].foo1();
ready
closure
t[Math.floor(Math.random() * 100)].foo2();
ready

Revisions

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