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>\n `\n\n\tconst toString = JSON.string\n function dynamicRegExp(node) {\n return RegExp(/width\\s*:\\s*(\\d+)\\s*px/i).test(tag);\n }\n \n function inlineRegExp(node) {\n return /width\\s*:\\s*(\\d+)\\s*px/i.test(tag);\n }\n \n function storedRegExp(node) {\n return reContains.test(tag);\n }\n \n function stringIndexOf(node) {\n return (tag).indexOf(width) > -1;\n }","version":"31"}var r;
var element = document.getElementById('foo');
var reContains = /width\s*:\s*(\d+)\s*px/i;
var tag = `<ins class='apsads'
style='display:inline-block;width:300px;height:250px'
data-aps-placement='YOUR_APS_PLACEMENT_ID'
data-aps-rendering-mode='script'
data-aps-click-tracker='\${CLICK_URL}'>
<script id="foo" src='https://z-na.amazon-adsystem.com/widgets/dfp/q?placement=YOUR_APS_PLACEMENT_ID'></script>
</ins>`
const toString = JSON.string
function dynamicRegExp(node) {
return RegExp(/width\s*:\s*(\d+)\s*px/i).test(tag);
}
function inlineRegExp(node) {
return /width\s*:\s*(\d+)\s*px/i.test(tag);
}
function storedRegExp(node) {
return reContains.test(tag);
}
function stringIndexOf(node) {
return (tag).indexOf(width) > -1;
}\n `\n\n\tconst toString = JSON.string\n function dynamicRegExp(node) {\n return RegExp(/width\\s*:\\s*(\\d+)\\s*px/i).test(tag);\n }\n \n function inlineRegExp(node) {\n return /width\\s*:\\s*(\\d+)\\s*px/i.test(tag);\n }\n \n function storedRegExp(node) {\n return reContains.test(tag);\n }\n \n function stringIndexOf(node) {\n return (tag).indexOf(width) > -1;\n }","version":"31"}Ready to run.
| Test | Ops/sec | |
|---|---|---|
| dynamic regexp | | ready |
| inline regexp | | ready |
| stored regexp | | ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.