mirror of
https://github.com/haml/haml.git
synced 2022-11-09 12:33:31 -05:00
Split benchmarks for html escaping
This commit is contained in:
parent
750915ad2b
commit
f6086794b0
3 changed files with 81 additions and 24 deletions
|
@ -14,9 +14,11 @@ env:
|
|||
- TASK=spec
|
||||
- TASK=rails:spec
|
||||
- TASK=bench TIME=20
|
||||
- TASK=bench TIME=20 HTML_ESCAPE=1
|
||||
matrix:
|
||||
allow_failures:
|
||||
- env: TASK=bench TIME=20
|
||||
- env: TASK=bench TIME=20 HTML_ESCAPE=1
|
||||
exclude:
|
||||
- env: TASK=spec
|
||||
gemfile: spec/rails/Gemfile
|
||||
|
@ -24,11 +26,17 @@ matrix:
|
|||
gemfile: Gemfile
|
||||
- env: TASK=bench TIME=20
|
||||
gemfile: spec/rails/Gemfile
|
||||
- env: TASK=bench TIME=20 HTML_ESCAPE=1
|
||||
gemfile: spec/rails/Gemfile
|
||||
- rvm: 2.1
|
||||
env: TASK=rails:spec
|
||||
- rvm: 2.1
|
||||
env: TASK=bench TIME=20
|
||||
- rvm: 2.1
|
||||
env: TASK=bench TIME=20 HTML_ESCAPE=1
|
||||
- rvm: 2.0.0
|
||||
env: TASK=rails:spec
|
||||
- rvm: 2.0.0
|
||||
env: TASK=bench TIME=20
|
||||
- rvm: 2.0.0
|
||||
env: TASK=bench TIME=20 HTML_ESCAPE=1
|
||||
|
|
|
@ -16,31 +16,20 @@ class Benchmarks
|
|||
@time = time
|
||||
@benches = []
|
||||
@versions = {}
|
||||
|
||||
@erb_code = File.read(File.dirname(__FILE__) + '/view.erb')
|
||||
@haml_code = File.read(File.dirname(__FILE__) + '/view.haml')
|
||||
@slim_code = File.read(File.dirname(__FILE__) + '/view.slim')
|
||||
|
||||
init_compiled_benches
|
||||
end
|
||||
|
||||
def init_compiled_benches
|
||||
context = Context.new
|
||||
|
||||
haml_ugly = Haml::Engine.new(@haml_code, format: :html5, ugly: true)
|
||||
haml_ugly.def_method(context, :run_haml_ugly)
|
||||
context.instance_eval %{
|
||||
def run_erubis; #{Erubis::Eruby.new(@erb_code).src}; end
|
||||
def run_slim_ugly; #{Slim::Engine.new.call @slim_code}; end
|
||||
def run_faml; #{Faml::Engine.new.call @haml_code}; end
|
||||
def run_hamlit; #{Hamlit::Engine.new.call @haml_code}; end
|
||||
}
|
||||
|
||||
bench('hamlit', Hamlit::VERSION) { context.run_hamlit }
|
||||
bench('erubis', Erubis::VERSION) { context.run_erubis }
|
||||
bench('slim', Slim::VERSION) { context.run_slim_ugly }
|
||||
bench('faml', Faml::VERSION) { context.run_faml }
|
||||
bench('haml', Haml::VERSION) { context.run_haml_ugly }
|
||||
def init_compiled_benches(escape_enabled)
|
||||
if escape_enabled
|
||||
@erb_code = File.read(File.dirname(__FILE__) + '/view.erb')
|
||||
@haml_code = File.read(File.dirname(__FILE__) + '/view.haml')
|
||||
@slim_code = File.read(File.dirname(__FILE__) + '/view.escaped.slim')
|
||||
init_escaped_benches
|
||||
else
|
||||
@erb_code = File.read(File.dirname(__FILE__) + '/view.erb')
|
||||
@haml_code = File.read(File.dirname(__FILE__) + '/view.haml')
|
||||
@slim_code = File.read(File.dirname(__FILE__) + '/view.slim')
|
||||
init_plain_benches
|
||||
end
|
||||
end
|
||||
|
||||
def run
|
||||
|
@ -56,6 +45,47 @@ class Benchmarks
|
|||
|
||||
private
|
||||
|
||||
# Totally the same as slim-template/slim's compiled bench.
|
||||
def init_plain_benches
|
||||
puts 'Compiled rendering benchmarks without HTML escape'
|
||||
context = Context.new
|
||||
|
||||
haml_ugly = Haml::Engine.new(@haml_code, format: :html5, ugly: true)
|
||||
haml_ugly.def_method(context, :run_haml_ugly)
|
||||
context.instance_eval %{
|
||||
def run_erubis; #{Erubis::Eruby.new(@erb_code).src}; end
|
||||
def run_slim_ugly; #{Slim::Engine.new.call @slim_code}; end
|
||||
def run_hamlit; #{Hamlit::Engine.new(escape_html: false).call @haml_code}; end
|
||||
}
|
||||
|
||||
bench('hamlit', Hamlit::VERSION) { context.run_hamlit }
|
||||
bench('erubis', Erubis::VERSION) { context.run_erubis }
|
||||
bench('slim', Slim::VERSION) { context.run_slim_ugly }
|
||||
bench('haml', Haml::VERSION) { context.run_haml_ugly }
|
||||
end
|
||||
|
||||
# slim-template/slim's compiled bench with HTML escaping.
|
||||
def init_escaped_benches
|
||||
puts 'Compiled rendering benchmarks with HTML escape'
|
||||
context = Context.new
|
||||
context.instance_eval("def header; '<script>'; end")
|
||||
|
||||
haml_ugly = Haml::Engine.new(@haml_code, format: :html5, ugly: true, escape_html: true)
|
||||
haml_ugly.def_method(context, :run_haml_ugly)
|
||||
context.instance_eval %{
|
||||
def run_erubis; #{Erubis::EscapedEruby.new(@erb_code).src}; end
|
||||
def run_slim_ugly; #{Slim::Engine.new.call @slim_code}; end
|
||||
def run_faml; #{Faml::Engine.new.call @haml_code}; end
|
||||
def run_hamlit; #{Hamlit::Engine.new.call @haml_code}; end
|
||||
}
|
||||
|
||||
bench('hamlit', Hamlit::VERSION) { context.run_hamlit }
|
||||
bench('slim', Slim::VERSION) { context.run_slim_ugly }
|
||||
bench('faml', Faml::VERSION) { context.run_faml }
|
||||
bench('erubis', Erubis::VERSION) { context.run_erubis }
|
||||
bench('haml', Haml::VERSION) { context.run_haml_ugly }
|
||||
end
|
||||
|
||||
def bench(name, version, &block)
|
||||
@benches.push([name, block])
|
||||
@versions[name] = version
|
||||
|
@ -70,4 +100,6 @@ class Benchmarks
|
|||
end
|
||||
|
||||
time = (ENV['TIME'] || 5).to_i
|
||||
Benchmarks.new(time).run
|
||||
bench = Benchmarks.new(time)
|
||||
bench.init_compiled_benches(ENV['HTML_ESCAPE'])
|
||||
bench.run
|
||||
|
|
17
benchmarks/view.escaped.slim
Normal file
17
benchmarks/view.escaped.slim
Normal file
|
@ -0,0 +1,17 @@
|
|||
doctype html
|
||||
html
|
||||
head
|
||||
title Simple Benchmark
|
||||
body
|
||||
h1 = header
|
||||
- unless item.empty?
|
||||
ul
|
||||
- for i in item
|
||||
- if i[:current]
|
||||
li
|
||||
strong = i[:name]
|
||||
- else
|
||||
li
|
||||
a href==i[:url] = i[:name]
|
||||
- else
|
||||
p The list is empty.
|
Loading…
Reference in a new issue