Added a Rake task for benchmarking. Use with rake benchmark (TIMES=n)

git-svn-id: svn://hamptoncatlin.com/haml/trunk@36 7063305b-7217-0410-af8c-cdc13e5119b9
This commit is contained in:
packagethief 2006-09-12 14:50:13 +00:00
parent 5374974646
commit 1a2040b1d9
2 changed files with 15 additions and 7 deletions

View File

@ -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'

View File

@ -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