New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Swig or Nunjucks? #179
Comments
This has come up before: |
Thanks for the link mkoryak, I did not see any benchmarks though. What about speed? |
Nunjucks has bench, but seems no compare with swig. |
Hi @jlongster, I write some code to compare nunjucks with swig, would you like review it? I don't know why nunjuck is faster than swig when render file, however the opposite result when render string. |
@popomore You're benchmark looks good. Nunjucks is fast when using file because the template is cached in between renders, and the code it generates is really fast. So you're basically just executing some JavaScript when rending a template. Rendering straight from a string each time is a lot slower because it hits the compiler and needs to be compiled to JS every single time. Additionally, since a new JS function is being run each time, the compiler never has a chance to trace and optimize it internally. This is a good example of why it's crazy to focus on optimizing the compiler, when you really just need to optimize the generated code and make sure you have a good caching strategy. For client-side browsers, this means a good strategy for using precompiled templates, which nunjucks has and swig doesn't. I see that you configured swig to cache the file template in memory, so I'm not sure why it is much slower even when caching the compiled code. |
Also note that you shouldn't spend too much time benchmarking templates -- most of the time it is not the bottleneck. But it's nice to see nunjucks perform so well. |
|
Thanks James, I have another question that can I use precompile in server side and is it recommended?— On Wed, Jan 22, 2014 at 11:56 PM, James Long notifications@github.com
|
No, you shouldn't use precompiled templates on the server-side (I think it even references |
Thanks for your advise. |
About benchmarks, just wanted to post this link here: http://jsperf.com/dot-nunjucks-mustache/11 |
@apfelbox cool benchmark, but unless performance is your number one problem, then I wouldn't select a framework based on its performance ;) |
Yeah, the gist is that it's competitive so we're ok. Precompiled templates are the important benchmark here, and that benchmark varies quite a bit between browsers. On average precompiled nunjucks beats or meets all the other ones except doT (which does seem to be a lot faster, but I don't know anything about it, it's probably a lot simpler). On my computer in Firefox nightly nunjucks precompiled comes in at 11,505, while dust.js precompiled is 12,291 and swig precompiled is only 2,134. |
@mkoryak I agree completely. I just posted the link for completeness sake. Personally I first look for things like security, ease of use, available features and difficulty to extend the system. On the other hand you don't need to waste CPU cycles unnecessarily. So you need to find a system which fulfills all of your requirements and is sufficiently fast. I just found out about nunjucks today, but it seems to fit this description. edit |
I was wrote a case a few time ago. https://jsfiddle.net/cLkjp99f/9/ The |
I am evaluating a templating engine along the lines of the Django/Jinja templating engines. How does Nunjucks stack against Swig?
Here is an overview which might help:
http://paularmstrong.github.io/node-templates/
Thanks
The text was updated successfully, but these errors were encountered: