dynamic templating

Benchmark created on


Test runner

Ready to run.

Testing in
TestOps/sec
template
const template = (template, parameters) => {
  const names = Object.keys(parameters);
  const values = Object.values(parameters);
  return new Function(...names, `return \`${template}\`;`)(...values);
};

template("my name is ${name} and i am ${age} years old", {name: "rodr", age: 22})
ready
regex
const template = (template, parameters) => {
  return Object.entries(parameters).reduce(
    (result, [arg, val]) => result.replace(`$\{${arg}}`, `${val}`),
    template
  );
};

template("my name is ${name} and i am ${age} years old", {name: "rodr", age: 22})
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.