String.Format underscore vs hot

Benchmark created on


Preparation HTML

<script src="http://documentcloud.github.com/underscore/underscore-min.js"></script>

<script>
  var hot = {};
  hot.format = function (string, context) {
                return string.replace(/\{(\S+)\}/g, function (str, key) { return context[key] });
        };
  
  _.templateSettings = {
    interpolate : /\{(.+?)\}/g
  };
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Underscore
_.template("{x}", {
    x : 1
});


_.template("{x}, {y}", {
    x : 1,
    y : 2
});

_.template("{x}, {y}, {z}", {
    x : 1,
    y : 2,
    z : 3
});
ready
Hot
hot.format("{x}", {
    x : 1
});

hot.format("{x}, {y}", {
    x : 1,
    y : 2
});

hot.format("{x}, {y}, {z}", {
    x : 1,
    y : 2,
    z : 3
});
ready

Revisions

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