jsPerf.app is an online JavaScript performance benchmark test runner & jsperf.com mirror. It is a complete rewrite in homage to the once excellent jsperf.com now with hopefully a more modern & maintainable codebase.
jsperf.com URLs are mirrored at the same path, e.g:
https://jsperf.com/negative-modulo/2
Can be accessed at:
https://jsperf.app/negative-modulo/2
Is it better to use native classList to check if an element is associated to an specific class or just search in the className string?
<p id="foo" class="foo bar zen"></p>
var elm = document.getElementById("foo");
var className = "bar";
function by_className() {
return (" " + elm.className + " ").indexOf(" "+className+" ") > -1; //extracted from https://github.com/julienw/dollardom/blob/master/$dom.dev.js
}
function by_classList() {
return elm.classList.contains(className);
}
Ready to run.
Test | Ops/sec | |
---|---|---|
Testing the className |
| ready |
classList.contains |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.