1

ビューをレンダリングするための最速のテンプレート エンジンを探しています。

私が理解しているように、erubis は ruby​​ で最速のテンプレート エンジンです。

私のユースケースは、スクリプトを介したテンプレートのレンダリングです。

gem の公式ページを見ると、最新のリリースは 2011 年でした。コミュニティがアクティブかどうかはわかりません。 https://rubygems.org/gems/erubis/versions

erubis テンプレート エンジンで ruby​​ 2.1 を使っている人はいますか?

ruby 2.1 で erubis を使用することは推奨されますか?

ありがとうアベイ

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
}

上記のベンチマーク スイートによると、Erbis は ERB レンダリングよりも 10 ~ 15 倍高速です。

于 2014-12-29T14:42:28.117 に答える