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
<span id="test" class="class0 class1 class2 class3 class4 class5 class6 class7 class8 class9 c1 c2 c3 c4 c5 c6 c7 c8 c9 cl1 cl2 cl3 cl4 cl5 cl6 cl7 cl8 cl9 cls1 cls2 cls3 cls4 cls5 cls6 cls7 cls8 cls9">Element</span>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
// cache element for speed
var __test = document.getElementById('test');
var _$test = $('#test');
Node.prototype.hasAnyClass = function(classNames) {
var i = -1,
classes = classNames.split(' '),
len = classes.length;
while (++i < len) {
if (this.classList.contains(classes[i])) {
return true;
}
}
return false;
};
Node.prototype.hasAllClasses = function(classNames) {
var i = -1,
classes = classNames.split(' '),
len = classes.length,
matches = 0;
while (++i < len) {
if (this.classList.contains(classes[i])) {
matches++;
}
}
return matches === len;
};
Ready to run.
Test | Ops/sec | |
---|---|---|
jQuery hasClass (any) |
| ready |
jQuery is (any) |
| ready |
jQuery attr match (any) |
| ready |
jQuery hasClass (all) |
| ready |
jQuery is (all) |
| ready |
native className indexOf (any) |
| ready |
native className indexOf (all) |
| ready |
native classList contains (any) |
| ready |
native classList contains (all) |
| ready |
custom hasAnyClass function (any) |
| ready |
custom hasAllClasses function (all) |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.