String.Format underscore vs hot (v6)

Revision 6 of this benchmark created on


Description

bad results in v2 from reconstructing the regex on method call, this fixes it.

Preparation HTML

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

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

Setup

var t1 = _.template("{x}"),
      t2 = _.template("{x} {y}"),
      t3 = _.template("{x} {y} {z}");

Test runner

Ready to run.

Testing in
TestOps/sec
Underscore
t1({
  x: 1
});


t2({
  x: 1,
  y: 2
});

t3({
  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.