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 strings = [...Array(100)].map(() => 'abc '.repeat(Math.random() * 30 | 0) + [...Array(1000)].map(() => `{${Math.random() * 100 | 0}}`).join('') + 'def'.repeat(Math.random() * 30 | 0));
const values = Object.fromEntries([...Array(60)].map((_, i) => [2 * i, (Math.random() * 1000 | 0).toString()]));
const escapeRegExpChars = (s) => s.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&');
function a(str, replacements) {
const regex = new RegExp(`{(${Object.keys(replacements).map(escapeRegExpChars).join('|')})}`, 'g');
return str.replace(regex, (_, key) => replacements[key] || '');
}
function b(str, replacements) {
return str.replace(/{([^} ]+)}/g, (full, val) => val in replacements ? replacements[val] : full);
}
function c(str, replacements) {
return Object.entries(replacements).reduce((str, [key, value]) => str.replaceAll(`{${key}}`, value), str);
}
Ready to run.
Test | Ops/sec | |
---|---|---|
big regexp |
| ready |
check all brackets |
| ready |
multiple replace |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.