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 class="class1 class2">Test</span>
<span class="class1">Test</span>
<span class="class2">Test</span>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
$.fn.extend({
hasClassesForLoop: function(selectors) {
var self = this;
for (i in selectors) {
if (self.hasOwnProperty(i)) {
if ($(self).hasClass(selectors[i]))
return true;
}
}
return false;
}
});
$.fn.extend({
hasClassesRegex: function(selector) {
var classNamesRegex = new RegExp("( " + selector.replace(/ +/g, "").replace(/,/g, " | ") + " )"),
rclass = /[\n\t\r]/g,
i = 0,
l = this.length;
for (; i < l; i++) {
if (this[i].nodeType === 1 && classNamesRegex.test((" " + this[i].className + " ").replace(rclass, " "))) {
return true;
}
}
return false;
},
});
(function($) {
$.fn.hasAnyOfClasses = function() {
for (var i = 0, il = arguments.length; i<il; i++) {
if (this.hasClass(arguments[i])) return true;
}
return false;
}
})(jQuery);
Ready to run.
Test | Ops/sec | |
---|---|---|
hasclass |
| ready |
is |
| ready |
.hasClasses() with for loop |
| ready |
.hasClasses() with Regex |
| ready |
extended hasclass (plugin) |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.