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
Checking the performance cost of using a regexp instead of String#indexOf.
<div id="foo" class="a foo bar"></div>var r;
var element = document.getElementById('foo');
var cacheRegexp = {};
function cachedRegExp(node, _class) {
return (cacheRegexp[_class] || (cacheRegexp[_class] = RegExp('(?:^| )'+ _class +'(?: |$)'))).test(node.className);
}
var cacheClassName = {};
function cachedIndexOf(node, _class) {
var className = node.className;
return (cacheClassName[className] || (cacheClassName[className] = ' '+ className +' ')).indexOf(cacheClassName[_class] || (cacheClassName[_class] = ' '+ _class +' ')) > -1;
}Ready to run.
| Test | Ops/sec | |
|---|---|---|
| regexp | | ready |
| indexOf | | ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.