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
Is it faster to loop through an array of strings and call replace on each one? Or is it faster to call a large regexp with all of the strings at once.
function stripBusinessName1(business_name) {
//TODO: find original parser, I had a very good function for this
business_name = business_name.toLowerCase();
return business_name.replace(/corporation|\sand\s|\sllc|\sdba|\sbros|\sbrothers|\ssons|\scompany|\sincorporated/g, '').replace(/co$|inc$|corp$/g, '');
}
function stripBusinessName2(business_name) {
business_name = business_name.toLowerCase();
var remove_these = ['corporation', ' and ', ' llc', ' dba', ' bros', ' brothers', ' sons', ' company', ' incorporated'];
//co and inc can't be reliably removed through traditionally means, they must be at the end
var len = remove_these.length;
for (var i = 0; i < len; i++) {
business_name = business_name.replace(remove_these[i], '');
}
return business_name.replace(/co$|inc$|corp$/g, '');
}
function stripBusinessName3(business_name) {
//TODO: find original parser, I had a very good function for this
business_name = business_name.toLowerCase();
return business_name.replace(/corporation|\sand\s|\sllc|\sdba|\sbros|\sbrothers|\ssons|\scompany|\sincorporated|co$|inc$|corp$/g, '');
}
Ready to run.
Test | Ops/sec | |
---|---|---|
RegExp |
| ready |
Loop |
| ready |
RegExp Unchained |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.