Measure find or foreach (v3)

Revision 3 of this benchmark created on


Preparation HTML

<div id="test" class="business-bss"></div>	

Test runner

Ready to run.

Testing in
TestOps/sec
find
 const setBusinessLogo = () => {
    const logoMap = {
        // Default
        "_default": "travis-perkins.svg",

				// Overrides 
        "business-benchmarkkitchensjoinery": "benchmark.svg",
        "business-bss": "bss.svg",
        "business-ccf": "CCF.svg",
        "business-keylinecivilsspecialist": "keyline.svg",
        "business-keyline": "keyline.svg",
        "business-toolstation": "tool-station.svg",
        "business-travisperkinsplc": "travis-perkins-new.svg",
        "business-tfsolutions": "tfsolutions.svg",
        "business-staircraft": "staircraft.svg",
        "business-travisperkinsmanagedservices": "managed-services.svg"
    };

		// Find the first entry that satisfies
    const presentClass = Object
                 .keys(logoMap)
                 .find((k) => document.querySelector("#test").classList.contains(k));
    
		let path = logoMap[presentClass];
    if(!path) { path = logoMap._default; }
    console.log(path);
};

setBusinessLogo();
ready
foreach
const setBusinessLogo = () => {
    const logoMap = {
        // Default
        "_default": "travis-perkins.svg",

				// Overrides 
        "business-benchmarkkitchensjoinery": "benchmark.svg",
        "business-bss": "bss.svg",
        "business-ccf": "CCF.svg",
        "business-keylinecivilsspecialist": "keyline.svg",
        "business-keyline": "keyline.svg",
        "business-toolstation": "tool-station.svg",
        "business-travisperkinsplc": "travis-perkins-new.svg",
        "business-tfsolutions": "tfsolutions.svg",
        "business-staircraft": "staircraft.svg",
        "business-travisperkinsmanagedservices": "managed-services.svg"
    };

		let path = logoMap._default;
    for (const key in logoMap) {
    	if(document.querySelector("#test").classList.contains(key)) {
            path = logoMap[key];
            break;
        }
    }
    
    console.log(path);
};

setBusinessLogo();
ready
forof
const setBusinessLogo = () => {
    const logoMap = {
        // Default
        "_default": "travis-perkins.svg",

        // Overrides 
        "business-benchmarkkitchensjoinery": "benchmark.svg",
        "business-bss": "bss.svg",
        "business-ccf": "CCF.svg",
        "business-keylinecivilsspecialist": "keyline.svg",
        "business-keyline": "keyline.svg",
        "business-toolstation": "tool-station.svg",
        "business-travisperkinsplc": "travis-perkins-new.svg",
        "business-tfsolutions": "tfsolutions.svg",
        "business-staircraft": "staircraft.svg",
        "business-travisperkinsmanagedservices": "managed-services.svg"
    };

    let path = logoMap._default;

    for (const key of Object.keys(logoMap)) {
        if (document.querySelector("#test").classList.contains(key)) {
            path = logoMap[key];
            break;
        }
    }

    console.log(path);
};

setBusinessLogo();
ready

Revisions

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