Object comparison vs string comparison. (v4)

Revision 4 of this benchmark created on


Setup

const TYPE_THING = {
    name: "RECORD",
    longName: new Array(50).fill('z').join('')
};

const obj1 = { ...TYPE_THING };
const obj2 = { ...TYPE_THING };
const TEST_CASES = new Array(10000).fill(1);

const compareString = (comp1, comp2) => {
    return comp1.name === comp2.name;
}

const compareObjRef = (comp1, comp2) => {
    return comp1 === comp2;
}

const compareLongString = (comp1, comp2) => {
    return comp1.longName === comp2.longName;
}

Test runner

Ready to run.

Testing in
TestOps/sec
comparison to string
const results = TEST_CASES.map(()=> compareString(obj1,obj2))
ready
comparison to object ref
const results = TEST_CASES.map(()=> compareObjRef(obj1,obj2))
ready
comparison to long string
const results = TEST_CASES.map(()=> compareLongString(obj1,obj2))
ready

Revisions

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