handlebars or lodash

JavaScript performance comparison

Revision 4 of this test case created by tomByrer

Info

v4: Forked v3, updated libs, added alpha Lo-Dash 1.5.0.

Preparation code

<script src="//cdnjs.cloudflare.com/ajax/libs/handlebars.js/2.0.0-alpha.2/handlebars.js"></script>
<script src="//cdn.jsdelivr.net/lodash/2.4.1/lodash.min.js"></script>
<script>var lodash = _.noConflict();</script>
<script src="//rawgithub.com/lodash/lodash/0d9c7df88bf35c357db21d169d97d52ecbe0c967/dist/lodash.js"></script>
<script>
Benchmark.prototype.setup = function() {
    var hb = []
    var ld = []
    _.times(50, function (item) {
        hb.push(Handlebars.compile("<div class='{{className}}'>{{item}}</div>{{#if fun}}<li><div><div>{{fun}}</div></div></li>{{/if}}"))
        ld.push(_.template("<div class='<%= className %>'><%= item %></div><% if(fun) { %><li></li><% } %><div><div><%= fun %></div></div>"))
    })
};
</script>

Preparation code output

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
Lodash 2.4.1
lodash.each(ld, function (item, key) {
  item({
     className: "z_item",
     item: "title",
     fun: key % 2 == 0
  })
})
pending…
Hb
_.each(hb, function (item, key) {
  item({
     className: "z_item",
     item: "title",
     fun: key % 2 == 0
  })
})
pending…
Lo-Dash alpha
_.each(ld, function (item, key) {
  item({
     className: "z_item",
     item: "title",
     fun: key % 2 == 0
  })
})
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

0 comments

Add a comment