Hacker News new | past | comments | ask | show | jobs | submit login

It's based on EJS. So it's indeed really similar to underscore. In fact, we benchmarked against underscore's template function and EJS and, at least in our templates, achieved better performance (Not very scientific: we got averages out of 200000 renders). It offers breakable printable blocks, and very nice debuggability.



I don't suppose you have a jsperf link to contrast and compare? I'm assuming swapping between the 2 isn't all that straightforward?


I'll try to do a /proper/ benchmark (Different cases, different types of templates, and such). Because the tests were with a simple template that had all the shared features. When I do, I'll add it to the README.

It's not that complicated, swaping between the two. they're basically the same if you don't use breaking printable blocks. So you just change:

    tm = _.template(string);
    tm(context);
to

    tm = new Thulium({template : string}).parseSync().renderSync(context);
It's different in that you do the initialization, parsing and rendering in different steps. TBH, with smallish templates, I found Thulium to be about 10µs faster. Which in most cases, is negligible. So if you're already using underscore, you probably shouldn't change everything. But if you need extra features like wrapping the output of a function in form tags or something like that, you can do it really easily with thulium. (Porting some of our helpers from EJS to Thulium meant a reduction of many lines of code and complexity.)


Updated with a JSPerf: http://jsperf.com/thulium-vs-underscore-and-ejs ... Tm runs faster in chrome/node... Underscore wins in firefox. So we'll need to get to work in optimizing stuff for firefox too :)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: