Add tenjin benchmark

This commit is contained in:
Takashi Kokubun 2015-03-09 16:08:19 +09:00
parent 982d4ced8a
commit 3db13fb80a
4 changed files with 38 additions and 8 deletions

1
.gitignore vendored
View File

@ -11,4 +11,5 @@
*.so *.so
*.o *.o
*.a *.a
*.cache
mkmf.log mkmf.log

View File

@ -10,6 +10,7 @@ require 'erubis'
require 'fast_haml' require 'fast_haml'
require 'haml' require 'haml'
require 'slim' require 'slim'
require 'tenjin'
require 'tilt' require 'tilt'
class Benchmarks class Benchmarks
@ -19,6 +20,7 @@ class Benchmarks
@erb_code = File.read(File.dirname(__FILE__) + '/view.erb') @erb_code = File.read(File.dirname(__FILE__) + '/view.erb')
@haml_code = File.read(File.dirname(__FILE__) + '/view.haml') @haml_code = File.read(File.dirname(__FILE__) + '/view.haml')
@slim_code = File.read(File.dirname(__FILE__) + '/view.slim') @slim_code = File.read(File.dirname(__FILE__) + '/view.slim')
@rbhtml_path = File.dirname(__FILE__) + '/view.rbhtml'
init_compiled_benches init_compiled_benches
end end
@ -28,6 +30,7 @@ class Benchmarks
erubis = Erubis::Eruby.new(@erb_code) erubis = Erubis::Eruby.new(@erb_code)
fast_erubis = Erubis::FastEruby.new(@erb_code) fast_erubis = Erubis::FastEruby.new(@erb_code)
haml_ugly = Haml::Engine.new(@haml_code, format: :html5, ugly: true) haml_ugly = Haml::Engine.new(@haml_code, format: :html5, ugly: true)
tenjin = Tenjin::Engine.new.get_template(@rbhtml_path)
context = Context.new context = Context.new
@ -39,15 +42,17 @@ class Benchmarks
def run_fast_erubis; #{fast_erubis.src}; end def run_fast_erubis; #{fast_erubis.src}; 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_fast_haml; #{FastHaml::Engine.new.call @haml_code}; end def run_fast_haml; #{FastHaml::Engine.new.call @haml_code}; end
def run_tenjin; _buf = ''; #{tenjin.script}; end
} }
bench('erb') { context.run_erb }
bench('erubis') { context.run_erubis } bench('erubis') { context.run_erubis }
bench('tenjin') { context.run_tenjin }
bench('fast erubis') { context.run_fast_erubis } bench('fast erubis') { context.run_fast_erubis }
bench('temple erb') { context.run_temple_erb }
bench('slim') { context.run_slim_ugly }
bench('haml') { context.run_haml_ugly }
bench('fast_haml') { context.run_fast_haml } bench('fast_haml') { context.run_fast_haml }
bench('slim') { context.run_slim_ugly }
bench('temple erb') { context.run_temple_erb }
bench('erb') { context.run_erb }
bench('haml') { context.run_haml_ugly }
end end
def run def run

23
benchmarks/view.rbhtml Normal file
View File

@ -0,0 +1,23 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Simple Benchmark</title>
</head>
<body>
<h1>#{ header }</h1>
<?rb unless item.empty? ?>
<ul>
<?rb for i in item ?>
<?rb if i[:current] ?>
<li><strong>#{ i[:name] }</strong></li>
<?rb else ?>
<li><a href="#{ i[:url] }">#{ i[:name] }</a></li>
<?rb end ?>
<?rb end ?>
</ul>
<?rb else ?>
<p>The list is empty.</p>
<?rb end ?>
</body>
</html>

View File

@ -25,4 +25,5 @@ Gem::Specification.new do |spec|
spec.add_development_dependency "haml" spec.add_development_dependency "haml"
spec.add_development_dependency "rake" spec.add_development_dependency "rake"
spec.add_development_dependency "slim" spec.add_development_dependency "slim"
spec.add_development_dependency "tenjin"
end end