static obj vs static get

Benchmark created on


Setup

var staticObj = /** @class */ (function () {
    function staticObj() {
    }
    staticObj.bar = {
        a: "i am a cat",
        b: "i am a dog",
        c: "i am a cow i guess",
        d: "zslejfklsejfkl",
        e: "lkjkl",
        f: "klajhragkjhgrask",
        g: "kjkljl",
        h: "y89iuhghjftg",
        i: "hgkj",
        j: "hjgkl;lihkugjh",
        k: "gyuhjbkoiuigyh",
        l: "ghjb",
        m: "ghkj",
        n: "huigvucyft",
        o: "ghkj",
        p: "huig",
        q: "jghjkjl",
        r: "huigyuftydcghvjhbkh",
        s: "jkhg",
        t: "ftghv",
        u: "hjgklk;ljhkgjf",
        v: "gjhuiou",
        w: "hgjyu",
        x: "gjh",
        y: "h",
        z: "drtytfuygiuhoijpoohuigyu",
    };
    return staticObj;
}());
var staticGet = /** @class */ (function () {
    function staticGet() {
    }
    staticGet.getBar = function () {
        var alpha = {
            a: "i am a cat",
            b: "i am a dog",
            c: "i am a cow i guess",
            d: "zslejfklsejfkl",
            e: "lkjkl",
            f: "klajhragkjhgrask",
            g: "kjkljl",
            h: "y89iuhghjftg",
            i: "hgkj",
            j: "hjgkl;lihkugjh",
            k: "gyuhjbkoiuigyh",
            l: "ghjb",
            m: "ghkj",
            n: "huigvucyft",
            o: "ghkj",
            p: "huig",
            q: "jghjkjl",
            r: "huigyuftydcghvjhbkh",
            s: "jkhg",
            t: "ftghv",
            u: "hjgklk;ljhkgjf",
            v: "gjhuiou",
            w: "hgjyu",
            x: "gjh",
            y: "h",
            z: "drtytfuygiuhoijpoohuigyu",
        };
        return alpha;
    };
    return staticGet;
}());

Test runner

Ready to run.

Testing in
TestOps/sec
staticObj
var longStrsObj = 0;
Object.keys(staticObj.bar).forEach(function (val) {
    if (staticObj.bar[val].length > 10) {
        longStrsObj++;
    }
});
console.log(longStrsObj);
ready
staticGet
var longStrsGet = 0;
Object.keys(staticGet.getBar()).forEach(function (val) {
    if (staticGet.getBar()[val].length > 10) {
        longStrsGet++;
    }
});
console.log(longStrsGet);
ready

Revisions

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