Ruby 2.1 with erubis Template Engine

后端 未结 1 1590
南笙
南笙 2021-01-16 03:40

We are looking for fastest template engine for rendering of views.

As i understand erubis is the fastest template engine in ruby.

My usecase is render templa

1条回答
  •  醉梦人生
    2021-01-16 04:20

    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
    }
    

    As per above benchmark suite Erubis is 10-15 times faster then ERB rendering.

    0 讨论(0)
提交回复
热议问题