1

我们正在寻找最快的模板引擎来渲染视图。

据我了解,erubis 是 ruby​​ 中最快的模板引擎。

我的用例是通过脚本渲染模板。

查看 gem 官方页面,它的最新版本是 2011 年。不确定社区是否活跃。 https://rubygems.org/gems/erubis/versions

有人使用 ruby​​ 2.1 和 erubis 模板引擎吗?

是否建议将 erubis 与 ruby​​ 2.1 一起使用?

谢谢阿拜

4

1 回答 1

4

我使用下面的代码片段在 ERB 和 erubis 渲染之间运行了基准测试。

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 倍。

于 2014-12-29T14:42:28.117 回答