Tests:
  • Factory

    x
     
    'use strict';
    function getInstance(param1) {
        var var1 = 'hello';
        var m1 = function (p) {
            return 'testing: ' + p;
        };
        return {
            getParam1: function () {
                return param1;
            },
            var1: var1,
            getResult: function (p) {
                return param1 + ', ' + var1 + ', ' + m1(p);
            }
        };
    }
    var a;
    var i = 0;
    var t1, t2;
    for (i; i < 1000; i++) {
      a = getInstance('A - ABC');
      t1 = a.getParam1() + a.var1;
      t2 = t1 + a.getResult('result A');
    }
  • Class

     
    'use strict';
    var TestClass = function () {
        function TestClass(param1) {
            this.param1 = param1;
            this.var1 = 'hello';
        }
        TestClass.prototype.m1 = function (p) {
            return 'testing: ' + p;
        };
        ;
        TestClass.prototype.getParam1 = function () {
            return this.param1;
        };
        TestClass.prototype.getResult = function (p) {
            return this.param1 + ', ' + this.var1 + ', ' + this.m1(p);
        };
        return TestClass;
    }();
    var b;
    var i = 0;
    var t1, t2;
    for (i; i < 1000; i++) {
      b = new TestClass('B - ABC');
      t1 = b.getParam1() + b.var1;
      t2 = t1 + b.getResult('result B');
    }
  • Factory (init outside of loop)

     
    'use strict';
    function getInstance(param1) {
        var var1 = 'hello';
        var m1 = function (p) {
            return 'testing: ' + p;
        };
        return {
            getParam1: function () {
                return param1;
            },
            var1: var1,
            getResult: function (p) {
                return param1 + ', ' + var1 + ', ' + m1(p);
            }
        };
    }
    var a;
    var i = 0;
    var t1, t2;
    a = getInstance('A - ABC');
    for (i; i < 1000; i++) {  
      t1 = a.getParam1() + a.var1;
      t2 = t1 + a.getResult('result A');
    }
  • Class (init outside of loop)

     
    'use strict';
    var TestClass = function () {
        function TestClass(param1) {
            this.param1 = param1;
            this.var1 = 'hello';
        }
        TestClass.prototype.m1 = function (p) {
            return 'testing: ' + p;
        };
        ;
        TestClass.prototype.getParam1 = function () {
            return this.param1;
        };
        TestClass.prototype.getResult = function (p) {
            return this.param1 + ', ' + this.var1 + ', ' + this.m1(p);
        };
        return TestClass;
    }();
    var b;
    var i = 0;
    var t1, t2;
    b = new TestClass('B - ABC');
    for (i; i < 1000; i++) {
      t1 = b.getParam1() + b.var1;
      t2 = t1 + b.getResult('result B');
    }
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    Factory
    Class
    Factory (init outside of loop)
    Class (init outside of loop)

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 8 years ago)
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.59 Safari/537.36
Chrome 54 on Windows
View result in a separate tab
Test name Executions per second
Factory 6546.8 Ops/sec
Class 5493.8 Ops/sec
Factory (init outside of loop) 11802.5 Ops/sec
Class (init outside of loop) 6966.3 Ops/sec