require 'test_helper' require 'haml' class PerformanceTest < ActiveSupport::TestCase GARA_EXAMPLE =<<-RUBY html(lang: "en") { head { meta charset: 'utf-8' meta name: 'viewport', content: "width=device-width, initial-scale=1.0" stylesheet_link_tag "application", media: 'all', 'data-turbolinks-track' => true csrf_meta_tags } body { h1 "Hello" para "Some text" javascript_include_tag "application" } } RUBY ERB_EXAMPLE = <<-ERB <%= stylesheet_link_tag 'application' %> <%= csrf_meta_tags %>

Hello

Some text

<%= javascript_include_tag 'application' %> ERB HAML_EXAMPLE = <<-HAML %html{:xmlns => "http://www.w3.org/1999/xhtml", :lang => "en", 'xml:lang' => "en"} %head %meta{'http-equiv' => "Content-Type", 'content' => "text/html; charset=UTF-8"} %meta{ 'charset' => 'utf-8'} %meta{'name' => 'viewport', 'content' => 'width=device-width, initial-scale=1.0'} = stylesheet_link_tag 'application' = csrf_meta_tags %body %h1 Hello %p Some text = javascript_include_tag 'application' HAML # class Context def javascript_include_tag(name, *args) %Q() end def stylesheet_link_tag(name, *args) %Q() end def csrf_meta_tags %Q( ) end # end def assigns {} end def measure_time(count) start_time = Time.now 1.upto(100) { yield } end_time = Time.now return end_time - start_time end # test "performance is okay" do # duration = measure_time(100) { ExpressTemplates.render(self, "#{GARA_EXAMPLE}") } # assert_operator 1.0, :>, duration # end # test "performance no more than 3.5x slower than erubis" do # eruby = Erubis::Eruby.new # duration_erb = measure_time(100) { eval(eruby.convert(ERB_EXAMPLE)) } # duration_express_templates = measure_time(100) { ExpressTemplates.render(self, "#{GARA_EXAMPLE}") } # assert_operator 4.0, :>, (duration_express_templates/duration_erb) # end # test "performance better than haml" do # duration_haml = measure_time(100) { Haml::Engine.new(HAML_EXAMPLE).render(self) } # duration_express_templates = measure_time(100) { ExpressTemplates.render(self, "#{GARA_EXAMPLE}") } # assert_operator 0.5, :>, (duration_express_templates/duration_haml) # end end