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 reContains = /(?:^| )foo(?: |$)/;
const reContainsConst = RegExp(' /(?:^| )foo(?: |$)/');
function dynamicRegExp(node) {
return RegExp('(?:^| )foo(?: |$)').test(node.className);
}
function inlineRegExp(node) {
return /(?:^| )foo(?: |$)/.test(node.className);
}
function storedRegExp(node) {
return reContains.test(node.className);
}
function constRegExp(node) {
return reContainsConst.test(node.className);
}
function stringIndexOf(node) {
return (' ' + node.className + ' ').indexOf(' foo ') > -1;
}
Ready to run.
Test | Ops/sec | |
---|---|---|
dynamic regexp |
| ready |
inline regexp |
| ready |
stored regexp |
| ready |
string indexOf |
| ready |
const regex |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.