Rails 3.2 - haml vs. erb. Is haml faster? (february 2012)

▼魔方 西西 提交于 2020-01-02 00:52:14

问题


I am working on a project and I am still thinking about using HAML (beautiful code, less size of view files) instead of classic ERB template.

My worries why I didn't do it yet are the speed of generating views - I read an articles/benchmarks and there was almost always HAML slower than ERB - but the truth is, that the articles are 2-3 years old.

So my question is, how looks the comparison these two template systems now, in the start of 2012?


回答1:


Here are some benchmarks from someone in Nov 2011. You should be able to cd to your haml directory and run rake benchmark. I say "should" because you'll need to get the proper dependencies installed in order to run that task. I played around with it for a few minutes but no luck locally. The relevant file is haml/test/benchmark.rb.

EDIT: I did find some more information for you. Someone else had the same trouble as me trying to get benchmarks working locally, so they rolled their own. I forked that gist and added support for comparing haml to erb: https://gist.github.com/1807036. I used the same templates that the haml library uses to benchmark. Here are the results that I got running the code:

$ ruby benchmark.rb
       user     system      total        real
haml:  0.650000   0.000000   0.650000 (  0.651584)
erb:  0.540000   0.000000   0.540000 (  0.534727)

I used ruby 1.9.3-p0, haml 3.1.4.




回答2:


There are already a bunch of debates documented on the web.

But when We have an application where we used ERB exclusively. Why should we try to make the switch to HAML? To me, it's a waste of time and a poor decision that wouldn't provide many benefits. While our code would suddenly be cleaner and a little more beautiful in HAML, we'd waste precious hours converting ERB to HAML. We have so many other important things to do, why waste that time on something so pointless in this case?

It's all relative. You don't need to use HAML instead of ERB. ERB can do all the same things. They are just different tools for the same job.



来源:https://stackoverflow.com/questions/9245854/rails-3-2-haml-vs-erb-is-haml-faster-february-2012

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!