Constructor vs Object literal x+1

Benchmark created by Nevallem on


Setup

function Test() {
        this.x = 32768;
        this.y = 65536;
    }
    
    Test.prototype.run = function() {
        var i,
                result = 0;
    
        for ( i = 0; i < this.x; i++ ) {
                result += this.y;
        }
    
        return result;
    };
    
    var test = {
        x: 32768,
        y: 65536
    };
    
    test.run = function() {
        var i,
                result = 0;
    
        for ( i = 0; i < this.x; i++ ) {
                result += this.y;
        }
    
        return result;
    };

Test runner

Ready to run.

Testing in
TestOps/sec
Constructor
( new Test() ).run();
ready
Object literal
test.run()
ready

Revisions

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

  • Revision 1: published by Nevallem on