Current (v2)

Revision 2 of this benchmark created on


Preparation HTML

<section class="module--PageHeaderV2"></section>
<section class="module--NavigationV2"></section>
<section class="module--CardModuleV2"></section>
<section class="module--IconGridV2"></section>
<section class="module--ContactV2"></section>
<section class="module--TestV2"></section>

Test runner

Ready to run.

Testing in
TestOps/sec
Current
if( document.querySelectorAll(".module--PageHeaderV2").length ) {
	document.querySelectorAll(".module--PageHeaderV2").forEach(el => {
        // do stuff
    });
}
if( document.querySelectorAll(".module--NavigationV2").length ) {
	document.querySelectorAll(".module--NavigationV2").forEach(el => {
        // do stuff
    });
}
if( document.querySelectorAll(".module--CardModuleV2").length ) {
	document.querySelectorAll(".module--CardModuleV2").forEach(el => {
        // do stuff
    });
}
if( document.querySelectorAll(".module--IconGridV2").length ) {
	document.querySelectorAll(".module--IconGridV2").forEach(el => {
        // do stuff
    });
}
if( document.querySelectorAll(".module--ContactV2").length ) {
	document.querySelectorAll(".module--ContactV2").forEach(el => {
        // do stuff
    });
}
if( document.querySelectorAll(".module--TestV2").length ) {
	document.querySelectorAll(".module--TestV2").forEach(el => {
        // do stuff
    });
}
ready
New
document.querySelectorAll(".module").forEach(el => {
    let classes = el.classList;
    if( classes.contains("module--PageHeaderV2") ) {

    } else if( classes.contains("module--NavigationV2") ) {

    } else if( classes.contains("module--CardModuleV2") ) {

    } else if( classes.contains("module--IconGridV2") ) {

    } else if( classes.contains("module--ContactV2") ) {

    } else if( classes.contains("module--TestV2") ) {

    }
});
ready
New - Regex
document.querySelectorAll(".module").forEach(el => {
    let classes = el.classList;
    let moduleMatch = el.className.match(/(module\-\-)(?:\S+)/g);
    let className = moduleMatch[0].split("--")[1];
    if( className === "PageHeaderV2" ) {

    } else if( className === "NavigationV2" ) {

    } else if( className === "CardModuleV2" ) {

    } else if( className === "IconGridV2" ) {

    } else if( className === "ContactV2" ) {

    } else if( className === "TestV2" ) {

    }
});
ready
New - Specific Selector
document.querySelectorAll("section.module").forEach(el => {
    let classes = el.classList;
    if( classes.contains("module--PageHeaderV2") ) {

    } else if( classes.contains("module--NavigationV2") ) {

    } else if( classes.contains("module--CardModuleV2") ) {

    } else if( classes.contains("module--IconGridV2") ) {

    } else if( classes.contains("module--ContactV2") ) {

    } else if( classes.contains("module--TestV2") ) {

    }
});
ready
New - Regex Specific Selector
document.querySelectorAll("section.module").forEach(el => {
    let classes = el.classList;
    let moduleMatch = el.className.match(/(module\-\-)(?:\S+)/g);
    let className = moduleMatch[0].split("--")[1];
    if( className === "PageHeaderV2" ) {

    } else if( className === "NavigationV2" ) {

    } else if( className === "CardModuleV2" ) {

    } else if( className === "IconGridV2" ) {

    } else if( className === "ContactV2" ) {

    } else if( className === "TestV2" ) {

    }
});
ready

Revisions

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