Object VS Function Constructor

Benchmark created on


Setup

var tmpObject = {
        object1: {test: 'test'},
        string1: 'test1',
        string2: 'test2',
        string3: 'test3',
        string4: 'test4',
        string5: 'test5',
        string6: 'test6',
        string7: 'test7',
        string8: 'test8',
        string9: 'test9',
        string10: 'test10',
        int1: 1,
        int2: 2,
        int3: 3,
        int4: 4,
        int5: 5,
        int6: 6,
        int7: 7,
        int8: 8,
        int9: 9,
        int10: 10,
        float1: 0.1,
        float2: 0.2,
        float3: 0.3,
        float4: 0.4,
        float5: 0.5,
        float6: 0.6,
        float7: 0.7,
        float8: 0.8,
        float9: 0.9,
        float10: 0.10
    }

Teardown


    var tmpFunction = new function() {
        this.object1 = {test : 'test'};
        this.string1 = 'test1';
        this.string2 = 'test2';
        this.string3 = 'test3';
        this.string4 = 'test4';
        this.string5 = 'test5';
        this.string6 = 'test6';
        this.string7 = 'test7';
        this.string8 = 'test8';
        this.string9 = 'test9';
        this.string10 = 'test10';
        this.int1 = 1;
        this.int2 = 2;
        this.int3 = 3;
        this.int4 = 4;
        this.int5 = 5;
        this.int6 = 6;
        this.int7 = 7;
        this.int8 = 8;
        this.int9 = 9;
        this.int10 = 10;
        this.float1 = 0.1;
        this.float2 = 0.2;
        this.float3 = 0.3;
        this.float4 = 0.4;
        this.float5 = 0.5;
        this.float6 = 0.6;
        this.float7 = 0.7;
        this.float8 = 0.8;
        this.float9 = 0.9;
        this.float10 = 0.10;
    };
    
  

Test runner

Ready to run.

Testing in
TestOps/sec
Object
var tmp2 = '';
for (var i = 1; i <= 10; i++) {
    tmp2 += tmpObject['string' + i] + tmpObject['int' + i] + tmpObject['float' + i];
}
ready
Function
var tmp3 = '';
for (var i = 1; i <= 10; i++) {
    tmp3 += tmpFunction['string' + i] + tmpFunction['int' + i] + tmpFunction['float' + i];
}
ready

Revisions

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