Closure vs Class

Benchmark created by BoogieMan on


Setup

var testObject = {
      propertyOne: 1,
      propertyTwo: 'Two'
    };
    
    var testMethods = {
      methodOne: methodOne,
      methodTwo: methodTwo
    };
    
    testClass.prototype = testMethods;
    
    function combineObjects(objOne, objTwo) {
      var keys = Object.keys(objTwo);
      for (var ii = 0; ii < keys.length; ii++) {
        var key = keys[ii];
        var src = objTwo[key];
        objOne[key] = src;
      }
    }
    
    function methodOne() {
      return this.propertyOne;
    }
    
    function methodTwo() {
      return this.propertyTwo;
    }
    
    function testClass(object) {
      combineObjects(this, object);
    }

Test runner

Ready to run.

Testing in
TestOps/sec
Class
var instance = new testClass(testObject);
ready
Closure
combineObjects(testObject, testMethods);
ready

Revisions

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

  • Revision 1: published by BoogieMan on