Underscore.string sprintf() vs Lo-Dash template() vs SugarJS assign()

Benchmark created by Dbone on


Preparation HTML

<script src="//cdnjs.cloudflare.com/ajax/libs/lodash.js/2.4.1/lodash.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/underscore.string/2.3.3/underscore.string.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/sugar/1.4.1/sugar.min.js"></script>

Setup

_.mixin(_.str.exports());
    var sprintfTemplate = 'Hello, %1$s, %2$s and %3$s',
      sprintfValue1 = 'Joe',
      sprintfValue2 = 'Richard',
      sprintfValue3 = 'Larry',
      templateTemplate = 'Hello, <%= name1 %>, <%= name2 %> and <%= name3 %>',
      templateValue = {
        name1: 'Joe',
        name2: 'Richard',
        name3: 'Larry'
      },
      sugarTemplate = 'Hello, {1}, {2} and {3}',
      sugarValue1 = 'Joe',
      sugarValue2 = 'Richard',
      sugarValue3 = 'Larry';

Test runner

Ready to run.

Testing in
TestOps/sec
Underscore.string sprintf()
_.sprintf(sprintfTemplate, sprintfValue1, sprintfValue2, sprintfValue3);
ready
Lo-Dash template()
_.template(templateTemplate, templateValue);
ready
Sugar assign()
sugarTemplate.assign(sugarValue1, sugarValue2, sugarValue3);
ready

Revisions

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

  • Revision 1: published by Dbone on