1
0
Fork 0
mirror of https://github.com/haml/haml.git synced 2022-11-09 12:33:31 -05:00

Cleanup run-benchmarks.rb

This commit is contained in:
Takashi Kokubun 2015-11-22 20:21:36 +09:00
parent bec4444376
commit 607345228f

View file

@ -55,74 +55,28 @@ class SlimBenchmarks
@slim_code = File.read(File.dirname(__FILE__) + '/view.slim') @slim_code = File.read(File.dirname(__FILE__) + '/view.slim')
init_compiled_benches init_compiled_benches
# init_tilt_benches
# init_parsing_benches if slow
end end
def init_compiled_benches def init_compiled_benches
haml_pretty = Haml::Engine.new(@haml_code, format: :html5, escape_html: true)
haml_ugly = Haml::Engine.new(@haml_code, format: :html5, ugly: true, escape_html: true) haml_ugly = Haml::Engine.new(@haml_code, format: :html5, ugly: true, escape_html: true)
context = Context.new context = Context.new
haml_pretty.def_method(context, :run_haml_pretty)
haml_ugly.def_method(context, :run_haml_ugly) haml_ugly.def_method(context, :run_haml_ugly)
context.instance_eval %{ context.instance_eval %{
def run_erubis; #{Erubis::Eruby.new(@erb_code).src}; end def run_erubis; #{Erubis::Eruby.new(@erb_code).src}; end
def run_temple_erb; #{Temple::ERB::Engine.new.call @erb_code}; end
def run_fast_erubis; #{Erubis::FastEruby.new(@erb_code).src}; end
def run_slim_pretty; #{Slim::Engine.new(pretty: true).call @slim_code}; end
def run_slim_ugly; #{Slim::Engine.new.call @slim_code}; end def run_slim_ugly; #{Slim::Engine.new.call @slim_code}; end
def run_faml; #{Faml::Engine.new.call @haml_code}; end def run_faml; #{Faml::Engine.new.call @haml_code}; end
def run_hamlit; #{Hamlit::Engine.new.call @haml_code}; end def run_hamlit; #{Hamlit::Engine.new.call @haml_code}; end
} }
# bench('(1) erb') { context.run_erb }
bench("erubis v#{Erubis::VERSION}") { context.run_erubis } bench("erubis v#{Erubis::VERSION}") { context.run_erubis }
# bench('(1) fast erubis') { context.run_fast_erubis }
# bench('(1) temple erb') { context.run_temple_erb }
# bench('(1) slim pretty') { context.run_slim_pretty }
bench("slim v#{Slim::VERSION}") { context.run_slim_ugly } bench("slim v#{Slim::VERSION}") { context.run_slim_ugly }
# bench('(1) haml pretty') { context.run_haml_pretty }
bench("haml v#{Haml::VERSION}") { context.run_haml_ugly } bench("haml v#{Haml::VERSION}") { context.run_haml_ugly }
bench("faml v#{Faml::VERSION}") { context.run_faml } bench("faml v#{Faml::VERSION}") { context.run_faml }
bench("hamlit v#{Hamlit::VERSION}") { context.run_hamlit } bench("hamlit v#{Hamlit::VERSION}") { context.run_hamlit }
end end
def init_tilt_benches
tilt_erb = Tilt::ERBTemplate.new { @erb_code }
tilt_erubis = Tilt::ErubisTemplate.new { @erb_code }
tilt_temple_erb = Temple::ERB::Template.new { @erb_code }
tilt_haml_pretty = Tilt::HamlTemplate.new(format: :html5) { @haml_code }
tilt_haml_ugly = Tilt::HamlTemplate.new(format: :html5, ugly: true) { @haml_code }
tilt_slim_pretty = Slim::Template.new(pretty: true) { @slim_code }
tilt_slim_ugly = Slim::Template.new { @slim_code }
context = Context.new
bench('(2) erb') { tilt_erb.render(context) }
bench('(2) erubis') { tilt_erubis.render(context) }
bench('(2) temple erb') { tilt_temple_erb.render(context) }
bench('(2) slim pretty') { tilt_slim_pretty.render(context) }
bench('(2) slim ugly') { tilt_slim_ugly.render(context) }
bench('(2) haml pretty') { tilt_haml_pretty.render(context) }
bench('(2) haml ugly') { tilt_haml_ugly.render(context) }
end
def init_parsing_benches
context = Context.new
context_binding = context.instance_eval { binding }
bench('(3) erb') { ERB.new(@erb_code).result(context_binding) }
bench('(3) erubis') { Erubis::Eruby.new(@erb_code).result(context_binding) }
bench('(3) fast erubis') { Erubis::FastEruby.new(@erb_code).result(context_binding) }
bench('(3) temple erb') { Temple::ERB::Template.new { @erb_code }.render(context) }
bench('(3) slim pretty') { Slim::Template.new(pretty: true) { @slim_code }.render(context) }
bench('(3) slim ugly') { Slim::Template.new { @slim_code }.render(context) }
bench('(3) haml pretty') { Haml::Engine.new(@haml_code, format: :html5).render(context) }
bench('(3) haml ugly') { Haml::Engine.new(@haml_code, format: :html5, ugly: true).render(context) }
end
def run def run
Benchmark.ips do |x| Benchmark.ips do |x|
@benches.each do |name, block| @benches.each do |name, block|