diff --git a/Rakefile b/Rakefile index a90c47aa..a70ef857 100644 --- a/Rakefile +++ b/Rakefile @@ -6,13 +6,21 @@ $:.unshift File.join(File.dirname(__FILE__), "..", "lib") desc 'Default: run unit tests.' task :default => :test -desc 'Test the haml plugin.' +desc 'Test the HAML plugin' Rake::TestTask.new(:test) do |t| t.libs << 'lib' t.pattern = 'test/**/*_test.rb' t.verbose = true end +desc 'Benchmark HAML against ERb. The benchmark routine is run 100. Use TIMES=n to override' +task :benchmark do + puts '-'*51, "+ Benchmark: HAML vs. ERb", '-'*51 + puts "Running benchmark #{ENV['TIMES']} times..." if ENV['TIMES'] + puts `ruby test/benchmark.rb #{ENV['TIMES']}` + puts '-'*51 +end + desc 'Generate documentation for the haml plugin.' Rake::RDocTask.new(:rdoc) do |rdoc| rdoc.rdoc_dir = 'rdoc' diff --git a/test/benchmark.rb b/test/benchmark.rb index 1d3fad09..dcaf77f9 100644 --- a/test/benchmark.rb +++ b/test/benchmark.rb @@ -5,14 +5,14 @@ $:.unshift File.join(File.dirname(__FILE__), "..", "lib") require 'rubygems' require 'action_view' -include Haml::Helper +include Haml::Helpers ActionView::Base.register_template_handler("haml", Haml::Engine) @base = ActionView::Base.new(File.dirname(__FILE__)) -RUNS = 2000 -Benchmark.bm do |x| - x.report("haml: ") { RUNS.times { @base.render("templates/standard"); } } - x.report("rhtml:") { RUNS.times { @base.render( "rhtml/standard"); } } -end +RUNS = (ARGV[0] || 100).to_i +Benchmark.bm do |b| + b.report("haml: ") { RUNS.times { @base.render "templates/standard" } } + b.report("rhtml:") { RUNS.times { @base.render "rhtml/standard" } } +end