Class Pattern Comparisons: Object External Method Access

JavaScript performance comparison

Test case created by Donald Atkinson

Info

This is a smaller test group for Class Pattern Comparison. For background, it is advisable to go to the full test page

Like the previous series, this series evaluates external method access. In contrast to the previous series, this simply tests object methods. Due to the fact that these do not access data members, some of these tests are essentially copies of some of the internal static method access tests.

Method Considerations

All methods are simple and return a literal 0. Because 'this' is accesses data members, use of 'this' has been avoided. 'This' will be measured in the Object Member Access series of tests.

Additional Notes

The Modular Class Pattern has so many possible variations that it easily has the widest number of external calls.

Preparation code

<!-- Shim from es5-shim: Function.prototype.apply() -->
<script>(function(){var d=!1,b=Function.prototype.apply;try{d=isNaN.apply(null,{})}catch(e){}d||(Function.prototype.apply=function(c,a){return a?"object"!==typeof a||a instanceof Array||!("length"in a)?b.call(this,c,a):b.call(this,c,Array.from(a)):b.call(this,c)})})();</script>

<script>
var ProtoObject = function(cfg) {
    this.data = 0;
};
ProtoObject.prototype = {
    doSomething: function(value) {
        return 0;
    },
};

var ConstructedObject = function(cfg) {
    this.data = 0;

    function doHoistedSomething() {
        return 0;
    }
    this.doSomething = function() {
        return 0;
    };
    this.doHoistedSomething = doHoistedSomething;
};

var ClassModuleObject = (function(Class) {
    var syncPrivateAccess = false;

    function doSomething() {
        return 0;
    }
    function doStaticallyHoistedSomething() {
        return 0;
    }
    Class.prototype = {
        class: Class,
        doProtoSomething: function() {
            return 0;
        },
        doProtoSomethingHoisted: doSomething,
    };

    Class.create = function(cfg) {
        function doLocallyHoistedSomething() {
            return 0;
        }
        this.data = 0;
        this.doSomething = function() {
            return 0;
        }
        this.doLocallyHoistedSomething = doLocallyHoistedSomething;
        this.doStaticallyHoistedSomething = doStaticallyHoistedSomething;

    };

// Return the Actual Class
    return Class;
}(function(cfg){
    return this.class.create.apply(this, arguments);
}));

var constructed = new ConstructedObject(),
    proto = new ProtoObject(),
    modular = new ClassModuleObject();
</script>

Preparation code output

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
Proto
proto.doSomething();
pending…
Constructed
constructed.doSomething();
pending…
Constructed Hoisted
constructed.doHoistedSomething();
pending…
Modular (Proto)
modular.doProtoSomething();
pending…
Modular (Proto Hoisted)
modular.doProtoSomethingHoisted();
pending…
Modular (Constructed)
modular.doSomething()
pending…
Modular (Constructed Hoisted)
modular.doLocallyHoistedSomething()
pending…
Modular (Constructed Hoisted Statically)
modular.doStaticallyHoistedSomething();
pending…

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

Compare results of other browsers

0 comments

Add a comment