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
Additional comparison of className and getAttribute("class")
<div class=" this is just a test case mother someClass " id="someElement"></div>
<script>
var el = document.getElementById('someElement');
function hasClass(el, selector){if((el.className).indexOf(" "+selector)>-1) {
return true;
}
return false;
}
function hasClass2(el, selector) {
if ((" " + el.className).replace(/[\n\t]/g, " ").indexOf(" " + selector ) > -1) {
return true;
}
return false;
}
function hasClass3(el, selector) {
if (el.className.match("\b"+selector)){return false;}return true;}
</script>
Ready to run.
Test | Ops/sec | |
---|---|---|
hasClass3 |
| ready |
Pure JS (className) |
| ready |
Pure JS (getAttribute) |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.