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

This is one of the most varied and comprehensive series of tests. These tests evaluate the accessing of methods from within the external method calls. Because of the sheer variety of ways to do things within the Modular Class, it should be expected that it will be quite a bit longer than the other tests. This series additionally tests the running of private object methods.

Method Characteristics

There are two types of methods in this batch: the accessors, and the worker methods. Each accessor runs a specific worker methods. Each worker method returns a literal 0. For the purposes of this test, no accessor method is hoisted. Private worker methods are, by nature, hoisted.

Considerations

As mentioned in the previous method access tests, due to scoping within the Modular Class, the only real signifying difference between static and object is whether the method accesses a public(this), or object private property. This means that there is considerable overlap and that this series may not produce intuitive results.

Preparation code

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

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

    function workPrivately() {
        return 0;
    }
 
    this.accessPublic = function() {
        return this.workPublicly();
    };
    this.accessPrivate = function() {
        return workPrivately();
    };

    this.workPublicly = function(){
        return 0;
    };
};

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

    function workStatically() {
        return 0;
    }
    function doStaticallyHoistedSomething() {
        return 0;
    }
    Class.prototype = {
        class: Class,
        accessProtoWorker: function() {
            return this.workProto();
        },
        accessConstWorkerFromProto: function() {
            return this.workConstPublicly();
        },
        accessPrivateWorkerFromProto: function() {
            return this.accessConstPrivateWorker();
        },
        accessProtoHoistedWorker: function() {
            return this.workProtoHoisted();
        },
        accessStaticWorker: function() {
            return workStatically()
        },
        workProto: function() {
            return 0;
        },
        workProtoHoisted: workStatically
    };

    Class.create = function(cfg) {
        function workPrivately() {
            return 0;
        }
        this.data = 0;
       
        this.workConstPublicly = function() {
            return 0;
        };

        this.accessConstWorker = function() {
             return this.workConstPublicly();
        };
        this.accessConstPrivateWorker = function() {
             return workPrivately();
        };
        this.accessConstStaticWorker = function() {
             return workStatically();
        };
        this.accessProtoWorkerFromConst = function() {
             return this.workProto;
        };

    };

// 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>

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
var value = proto.access();
pending…
Constructed Public
var value = constructed.accessPublic();
pending…
Constructed Private
var value = constructed.accessPrivate();
pending…
Modular Proto Public
var value = modular.accessProtoWorker();
pending…
Modular Proto to Private Static
var value = modular.accessStaticWorker();
pending…
Modular Proto to Public Constructor
var value = modular.accessConstWorkerFromProto();
pending…
Modular Proto to Private Constructor
var value = modular.accessPrivateWorkerFromProto();
pending…
Modular Const Public
var value = modular.accessConstWorker();
pending…
Modular Const Private
var value = modular.accessConstPrivateWorker();
pending…
Modular Const to Static Private
var value = modular.accessConstStaticWorker();
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