String concat vs regex replace

Benchmark created on


Setup

var view = {
      name: "test",
      value: 5
    },
    template = "Hello, my name is {name} and my value is {value}",
    render = function fmt(s,a,r){r=/\{([^}]+)\}/g;return s.replace(r,function(_,m){return a[m]})};

Test runner

Ready to run.

Testing in
TestOps/sec
String join
//This would be an example of a compiled template
var rendered = "Hello, my name is " + view.name + " and my value is " + view.value;
ready
Using a regex
var rendered = render(template, view);
ready

Revisions

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