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
Addressing the issue provided in the following Stackoverflow question: Check if class exists somewhere in parent - vanilla JS http://stackoverflow.com/q/16863917/717221
Gist: https://gist.github.com/Fardinak/057f74cc22b15db35044
<div id="the-parent" class="also has class">
<div>
<div class="im-yo-dad">
<div id="missing-child"></div>
</div>
</div>
</div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
function hasParent(element, parentSelector) {
var potentialParents = document.querySelectorAll(parentSelector);
for(i in potentialParents) if(potentialParents[i].contains(element))
return potentialParents[i];
return false;
}
function hasSomeParentTheClass(element, classname) {
if (element.className.split(' ').indexOf(classname)>=0) return true;
return element.parentNode && hasSomeParentTheClass(element.parentNode, classname);
}
var child = document.getElementById('missing-child');
Ready to run.
Test | Ops/sec | |
---|---|---|
Query Selector - ID |
| ready |
Query Selector - Class |
| ready |
Query Selector - Mix |
| ready |
Recursive |
| ready |
For the curious mind |
| ready |
jQuery - ID |
| ready |
jQuery - Class |
| ready |
jQuery - Mix |
| ready |
jQuery - Complex |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.