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) {
return (el.className).indexOf(" "+selector+" ")>-1
}
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+"\b")){return true;}return false;}
function hasClass4(el, selector) {
var pattern = '/(.*)(' + selector + ')(.*)/gi';
return el.className.replace(pattern , '$2') != '';
}
</script>
Ready to run.
Test | Ops/sec | |
---|---|---|
hasClass3 |
| ready |
Pure JS (className) |
| ready |
Pure JS (getAttribute) |
| ready |
PureJS replace |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.