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="someClass" id="someElement"></div><script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script>
var el = document.getElementById('someElement');
function hasClass(el, selector) {
var className = " " + selector + " ";
if ((" " + el.className + " ").replace(/[\n\t]/g, " ").indexOf(className) > -1) {
return true;
}
return false;
}
function hasClass2(el, selector) {
return el.className.split(/\s+/g).indexOf(selector) !== -1;
}
function hasClass3(el, selector){
return (new RegExp('(\\s|^)' + selector + '(\\s|$)').test(el.className));
}
function hasClassString(el, c) {
var s = el.className, i = s.indexOf(c);
return i != -1 && (s.charCodeAt(i - 1) || 32) == 32 && (s.charCodeAt(i + c.length) || 32) == 32;
return false;
};
</script>
Ready to run.
Test | Ops/sec | |
---|---|---|
jQuery |
| ready |
Pure JS (className) |
| ready |
Pure JS (split) |
| ready |
RegExp |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.