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
Just seeing if it's possible to optimize the addClass and removeClass functions from Thomas Fuchs' very cool Zepto JavaScript mini-framework.
<p id="el" class="big blue">A DOM element with a className attribute.</p>
<script>
// zepto
function classRE(name) {
return new RegExp("(^|\\s)" + name + "(\\s|$)");
}
function addClass(el, name) {
return !classRE(name).test(el.className) && (el.className += (el.className ? ' ' : '') + name);
}
function removeClass(el, name) {
return el.className = el.className.replace(classRE(name), ' ').replace(/^\s+|\s+$/g, '');
}
// zepto 2
function addClass2(el, name) {
return !classRE(name).test(el.className) && (el.className += ' ' + name).replace(/^\s+/g, '');
}
function removeClass2(el, name) {
return el.className = el.className.replace(classRE(name), '');
}
var el = document.getElementById('el');
</script>
Ready to run.
Test | Ops/sec | |
---|---|---|
Zepto |
| ready |
Zepto 2 |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.