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 template = `Olá {{1}} 😄
Esse é um teste utilizando modelos {{1}} com imagens e botões
Enviado pelo {{2}}`;
const variables = [
{
"type": "text",
"text": "Daniel"
},
{
"type": "text",
"text": "Atendimento Boti"
}
]
function mergeParamsWithTemplateReplace(templatePlaceholder, variables, kind) {
return templatePlaceholder.replace(/\{\{(\d)\}\}/gm, (_match, p1) => {
return `${variables[p1 - 1][kind]}`;
});
};
function mergeParamsWithTemplateForEach(templatePlaceholder, variables, kind) {
variables.forEach((param, index) => {
const reg = new RegExp(`\\{\\{${index + 1}\\}\\}`, 'gm');
templatePlaceholder = templatePlaceholder.replace(reg, param[kind]);
});
return templatePlaceholder;
}
function mergeParamsWithTemplateForOf(templatePlaceholder, variables, kind) {
let index = 0;
for (const item of variables) {
index += 1;
templatePlaceholder = templatePlaceholder.replace(new RegExp(`\\{\\{${index}\\}\\}`, 'gm'), item[kind]);
}
return templatePlaceholder;
}
function mergeParamsWithTemplateFor(templatePlaceholder, variables, kind) {
for (let index = 0; index < variables.length; index++) {
const param = variables[index];
templatePlaceholder = templatePlaceholder.replace(new RegExp(`\\{\\{${index + 1}\\}\\}`, 'gm'), param[kind]);
}
return templatePlaceholder;
}
Ready to run.
Test | Ops/sec | |
---|---|---|
replace |
| ready |
forEach |
| ready |
for of |
| ready |
for |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.