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
Testing selector matching using (webkit|moz|ms|o)MatchesSelector
(implemented "matchesSelector
" in Firefox and webkit browsers)
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<div class="level1">
<div class="level2">
<div class="level3">
<div class="level4">
<div class="level5" id="foo">
</div>
<div class="level5">
</div>
<div class="level5">
</div>
</div>
</div>
</div>
</div>
<script>
(function(docEl, $) {
var matches = docEl.mozMatchesSelector || docEl.msMatchesSelector || docEl.oMatchesSelector || docEl.webkitMatchesSelector;
$.fn.matching = matches ?
function(selector) {
return matches.call(this[0], selector);
} : $.fn.is;
})(document.documentElement, jQuery);
var matchesSelector = function(thisObj, selector) {
var isSimpleSelector = /^[\w#.]\w*$/.test(selector);
if(isSimpleSelector) {
switch (selector.charAt(0)) {
case '#':
return thisObj.id === selector.slice(1);
break;
case '.':
return thisObj.classList.contains(selector.slice(1));
break;
default:
return thisObj.tagName === selector;
}
}
var parent = thisObj.parentNode,
tmp,
match = false;
if(parent) {
match = parent.querySelector(selector) === thisObj;
}
if(!match && (parent = thisObj.ownerDocument)) {
tmp = parent.querySelectorAll(selector);
for ( e in tmp ) if(tmp.hasOwnProperty(e)) {
match = tmp[e] === thisObj;
if(match)return true;
}
}
return match;
}
var $element = jQuery(jQuery('.level1 .level2 .level3 .level4 .level5')[0]); // Get first result and add wrap with jQuery object
var domEl = $element[0];
</script>
Ready to run.
Test | Ops/sec | |
---|---|---|
Using $.fn.is |
| ready |
Using mozMatchesSelector or webkitMatchesSelector |
| ready |
Native Implementation using querySelector on Parent Node |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.