Make benchmark.rb more standalone.

This commit is contained in:
Nathan Weizenbaum 2008-05-06 00:43:43 -07:00
parent a0c0005ebb
commit 500be8e3bd
2 changed files with 162 additions and 165 deletions

View File

@ -20,18 +20,9 @@ END
desc temp_desc.chomp
task :benchmark do
require 'test/benchmark'
puts "Running benchmarks #{ENV['TIMES']} times..." if ENV['TIMES']
times = ENV['TIMES'].to_i if ENV['TIMES']
Haml.benchmark(times || 100)
puts '-'*51
sh "ruby test/benchmark.rb #{ENV['TIMES']}"
end
# Benchmarking gets screwed up if some other tasks have been
# initialized.
unless ARGV[0] == 'benchmark'
# ----- Default: Testing ------
desc 'Default: run unit tests.'
@ -160,5 +151,3 @@ END
puts '-'*51
end
end

22
test/benchmark.rb Normal file → Executable file
View File

@ -1,3 +1,16 @@
#!/usr/bin/env ruby
times = (ARGV.first || 1000).to_i
if times == 0 # Invalid parameter
puts <<END
ruby #$0 [times=1000]
Benchmark Haml against various other templating languages and Sass
on its own.
END
exit 1
end
# There's a bizarre error where ActionController tries to load a benchmark file
# and ends up finding this.
# These declarations then cause it to break.
@ -24,10 +37,7 @@ rescue LoadError
raise "The Haml benchmarks require the benchwarmer gem, available from http://github.com/wycats/benchwarmer"
end
module Haml
# Benchmarks Haml against ERB, Erubis, and Markaby and Sass on its own.
def self.benchmark(runs = 100)
Benchmark.warmer(runs) do
Benchmark.warmer(times) do
columns :haml, :erb, :erubis, :mab
titles :haml => "Haml", :erb => "ERB", :erubis => "Erubis", :mab => "Markaby"
@ -79,10 +89,8 @@ module Haml
end
end
Benchmark.warmer(runs) do
Benchmark.warmer(times) do
sass_template = File.read("#{File.dirname(__FILE__)}/sass/templates/complex.sass")
report("Sass") { Sass::Engine.new(sass_template).render }
end
end
end