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
getElementsByClassName || getElementsById || getElementsByTagName || querySelectorAll
<div id="test" class="test"></div>
<script>
function query(_) {
var r;
if (r = /^\.([\w-]+)$/.exec(_)) {
return document.getElementsByClassName(r[1])
}
else if (r = /^\#([\w-]+)$/.exec(_)) {
return document.getElementById(r[1])
}
else if (/^[\w-]+$/.test(_)) {
return document.getElementsByTagName(_)
}
else {
return document.querySelectorAll(_)
}
}
</script>
Ready to run.
Test | Ops/sec | |
---|---|---|
complex query |
| ready |
complex querySelectorAll |
| ready |
complex querySelectorAll, one line |
| ready |
query(class) |
| ready |
querySelectorAll(class) |
| ready |
query(id) |
| ready |
querySelectorAll(id) |
| ready |
query(tag) |
| ready |
querySelectorAll(tag) |
| ready |
querySelector(id) |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.