Cleanup benchmark code

This commit is contained in:
Takashi Kokubun 2015-06-08 01:38:49 +09:00
parent 70ab3e2edf
commit b6445fcaf5
3 changed files with 5 additions and 50 deletions

View File

@ -5,13 +5,10 @@ $:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'), File.dirname(__FILE__
require_relative './context'
require 'benchmark/ips'
require 'erb'
require 'erubis'
require 'faml'
require 'haml'
require 'slim'
require 'tenjin'
require 'tilt'
require 'hamlit'
class Benchmarks
@ -20,32 +17,22 @@ class Benchmarks
@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')
@rbhtml_path = File.dirname(__FILE__) + '/view.rbhtml'
@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
erb = ERB.new(@erb_code)
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
haml_ugly = Haml::Engine.new(@haml_code, format: :html5, ugly: true)
haml_ugly.def_method(context, :run_haml_ugly)
context.instance_eval %{
def run_erb; #{erb.src}; end
def run_erubis; #{erubis.src}; end
def run_temple_erb; #{Temple::ERB::Engine.new.call @erb_code}; end
def run_fast_erubis; #{fast_erubis.src}; end
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_tenjin; _buf = ''; #{tenjin.script}; end
def run_hamlit; #{Hamlit::Engine.new.call @haml_code}; end
}
@ -54,14 +41,6 @@ class Benchmarks
bench('slim', Slim::VERSION) { context.run_slim_ugly }
bench('faml', Faml::VERSION) { context.run_faml }
bench('haml', Haml::VERSION) { context.run_haml_ugly }
if ENV['ALL']
erb_version = ERB.version.match(/\[([^ ]+)/)[1]
bench('tenjin', Tenjin::RELEASE) { context.run_tenjin }
bench('fast erubis', Erubis::VERSION) { context.run_fast_erubis }
bench('temple erb', Temple::VERSION) { context.run_temple_erb }
bench('erb', erb_version) { context.run_erb }
end
end
def run

View File

@ -1,23 +0,0 @@
<!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

@ -36,7 +36,6 @@ Gem::Specification.new do |spec|
spec.add_development_dependency "rspec", ">= 3"
spec.add_development_dependency "sass"
spec.add_development_dependency "slim"
spec.add_development_dependency "tenjin"
spec.add_development_dependency "therubyracer"
spec.add_development_dependency "unindent"
end