问题描述
我们正在寻找用于渲染视图的最快的模板引擎.
We are looking for fastest template engine for rendering of views.
据我所知,erubis是红宝石中最快的模板引擎.
As i understand erubis is the fastest template engine in ruby.
我的用例是通过脚本渲染模板.
My usecase is render templates through script.
查看gem官方页面,它的最新版本是2011年.不知道社区是否活跃. https://rubygems.org/gems/erubis/versions
Looking at the gem official page it's latest release was in 2011.Not sure if the community is active.https://rubygems.org/gems/erubis/versions
有人将ruby 2.1与erubis模板引擎一起使用吗?
Does anyone use ruby 2.1 with erubis template engine?
是否建议将erubis与ruby 2.1一起使用?
Is it recommended to use erubis with ruby 2.1?
谢谢阿比(Abhay)
ThanksAbhay
推荐答案
我使用以下代码段在ERB和erubis渲染之间运行了基准测试.
I ran benchmark between ERB and erubis rendering with below code snippet.
erubis_render_time = Benchmark.realtime {
template_content = File.read("#{Rails.root}/app/views/web/email_templates/erubis_benchmark_test.erb")
1000.times do |j|
email_body = Erubis::Eruby.new(template_content).result({welcome_mail_cta: "Shop Now", welcome_mail_string: "Welcome. Your account is activated"})
end
}
template_path = "/web/email_templates/benchmark_test"
erb_render_time = Benchmark.realtime {
1000.times do |j|
email_body = ActionController::Base.new.send(:render_to_string,
:template => template_path,
:layout => false,
:locals => {:data => {welcome_mail_cta: "Shop Now",
welcome_mail_string: "Welcome. Your account is activated"
}
}
)
end
}
按照上述基准套件,Erubis的渲染速度比ERB渲染快10到15倍.
As per above benchmark suite Erubis is 10-15 times faster then ERB rendering.
这篇关于带有erubis模板引擎的Ruby 2.1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!