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
const EMPTY_ARRAY = Object.freeze([]);
const VALUE_PLACEHOLDER_IN_FORMAT = '#';
const REGEX_TO_MATCH_VALUE_PLACEHOLDER = new RegExp(VALUE_PLACEHOLDER_IN_FORMAT, 'g')
const getDigitPlaceholderMatches = (phoneNumberFormat = '') => {
const digitPlaceholderMatches = phoneNumberFormat.match(REGEX_TO_MATCH_VALUE_PLACEHOLDER);
return digitPlaceholderMatches;
};
const getCountOfPhoneNumberDigits = phoneNumberFormat => {
const digitPlaceholderMatches = getDigitPlaceholderMatches(phoneNumberFormat) || EMPTY_ARRAY;
const countOfPhoneNumberDigits = digitPlaceholderMatches.length;
return countOfPhoneNumberDigits;
};
var getCountOfPhoneNumberDigitsUsingForLoop = function getCountOfPhoneNumberDigits(phoneNumberFormat) {
let count = 0;
for(let i = 0; i < phoneNumberFormat; i++) {
const curr = phoneNumberFormat[i];
if(curr === VALUE_PLACEHOLDER_IN_FORMAT)
count++;
}
return count;
};
const phoneNumberFormat1 = "(###) ###-####";
Ready to run.
Test | Ops/sec | |
---|---|---|
Using For Loop |
| ready |
Using RegExp |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.