Object build (v4)

Revision 4 of this benchmark created on


Test runner

Ready to run.

Testing in
TestOps/sec
Type A
function getResult() {
    var x, y, z;

    // Define x, y but not z
    x = 1;
    y = 2;

    var result = {};

    result ['a'] = 'a';
    result ['b'] = 'b';

    if (x !== undefined) {
        result ['x'] = x;
    }

    if (y !== undefined) {
      result ['y'] = y;
    }

    if (z !== undefined) {
      result ['z'] = z;
    }

    return result;
}


getResult();
ready
Type B
function getResult() {
    var x, y, z;

    // Define x, y but not z
    x = 1;
    y = 2;

    var result = {};
    result.a = 'a';
    result.b = 'b';
    result.x = x;
    result.y = y;
    result.z = z;
    for (var i in result) {
        if (result[i] === undefined) delete result[i];
    }

    return result;
}

getResult();
ready
Type C
function getResult() {
    var x, y, z;

    // Define x, y but not z
    x = 1;
    y = 2;

    var result = {};
    result.a = 'a';
    result.b = 'b';
    result.x = x;
    result.y = y;
    result.z = z;
    return JSON.parse(JSON.stringify(result));
}

getResult();
ready

Revisions

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