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
*.o
*.a
*.cache
mkmf.log

View File

@ -10,15 +10,17 @@ require 'erubis'
require 'fast_haml'
require 'haml'
require 'slim'
require 'tenjin'
require 'tilt'
class Benchmarks
def initialize
@benches = []
@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')
@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')
@rbhtml_path = File.dirname(__FILE__) + '/view.rbhtml'
init_compiled_benches
end
@ -28,8 +30,9 @@ class Benchmarks
erubis = Erubis::Eruby.new(@erb_code)
fast_erubis = Erubis::FastEruby.new(@erb_code)
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
haml_ugly.def_method(context, :run_haml_ugly)
context.instance_eval %{
@ -39,15 +42,17 @@ class Benchmarks
def run_fast_erubis; #{fast_erubis.src}; 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_tenjin; _buf = ''; #{tenjin.script}; end
}
bench('erb') { context.run_erb }
bench('erubis') { context.run_erubis }
bench('tenjin') { context.run_tenjin }
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('slim') { context.run_slim_ugly }
bench('temple erb') { context.run_temple_erb }
bench('erb') { context.run_erb }
bench('haml') { context.run_haml_ugly }
end
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 "rake"
spec.add_development_dependency "slim"
spec.add_development_dependency "tenjin"
end