Class Pattern Comparisons: Static 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

For most circumstances, the next few tests are the actual meat of the comparisons. Access to methods and data members often far outweighs initial load and creation. This is because most object/class methods must be able to interact with their own members. Additionally, other objects must be able to interact with them in a meaningful way.

Considerations

These access tests are substantially different than the previous tests due to the dramatically different nature of the class patterns.

Method Naming

All methods are named doSomethingStatically with the following provisions:

Additional Notes

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) {
    var dataPrivate = 0;
    this.dataPublic = 0;
};
ProtoObject.doSomethingStatically = function(){
   return 0;
};
ProtoObject.prototype = {
    doSomethingStatically: function() {
         return ProtoObject.doSomethingStatically();
    }
};

var ConstructedObject = function(cfg) {
    var dataPrivate = 0;

    this.dummy = 0;
    this.dataPublic = 0;

    function doHoistedSomethingStatically() {
         return 0;
    }
    this.doSomethingStatically = function() {
         return ConstructedObject.doSomethingStatically();
    };
    this.doHoistedSomethingStatically = doHoistedSomethingStatically;
};
ConstructedObject.doSomethingStatically = function(){
    return 0;
};

var ClassModuleObject = (function(Class) {

    Class.doSomethingStatically = function() {
        return 0;
    };
    function doSomethingStaticallyHoisted() {
        return 0;
    }
    Class.doSomethingStaticallyHoisted = doSomethingStaticallyHoisted;
   
    function doHoistedSomethingStatically() {
        return 0;
    }
    Class.prototype = {
        class: Class,
        doSomethingStatically: function(value) {
            return Class.doSomethingStatically();
        },
        doSomethingStaticallyHoisted: function() {
            return doSomethingStaticallyHoisted();
        },
        doHoistedSomethingStatically: doHoistedSomethingStatically
    };

    Class.create = function(cfg) {
        var dataPrivate = 50;

        this.dataPublic = 0;
    };

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

var proto = new ProtoObject(),
    constructed = new ConstructedObject(),
    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
External Proto (Class)
ProtoObject.doSomethingStatically();
pending…
Internal Proto (Object)
proto.doSomethingStatically();
pending…
External Constructor (Class)
ConstructedObject.doSomethingStatically();
pending…
Internal Constructor (Object)
constructed.doSomethingStatically();
pending…
Internal Constructor (Object/Hoisted)
constructed.doHoistedSomethingStatically();
pending…
External Modular (Class)
ClassModuleObject.doSomethingStatically();
pending…
External Modular (Class/Hoisted)
ClassModuleObject.doSomethingStaticallyHoisted();
pending…
Internal Modular (Object)
modular.doSomethingStatically();
pending…
Internal Modular (Object/Hoisted)
modular.doSomethingStaticallyHoisted();
pending…
Internal Modular (Object/Hoisted Function/Hoisted Definition)
modular.doHoistedSomethingStatically();
pending…
Unknown External (Class)
modular.class.doSomethingStatically();
pending…
Unknown External (Class/Hoisted)
modular.class.doSomethingStaticallyHoisted();
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