Make benchmark.rb more standalone.
This commit is contained in:
parent
a0c0005ebb
commit
500be8e3bd
13
Rakefile
13
Rakefile
|
@ -20,18 +20,9 @@ END
|
||||||
|
|
||||||
desc temp_desc.chomp
|
desc temp_desc.chomp
|
||||||
task :benchmark do
|
task :benchmark do
|
||||||
require 'test/benchmark'
|
sh "ruby test/benchmark.rb #{ENV['TIMES']}"
|
||||||
|
|
||||||
puts "Running benchmarks #{ENV['TIMES']} times..." if ENV['TIMES']
|
|
||||||
times = ENV['TIMES'].to_i if ENV['TIMES']
|
|
||||||
Haml.benchmark(times || 100)
|
|
||||||
puts '-'*51
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Benchmarking gets screwed up if some other tasks have been
|
|
||||||
# initialized.
|
|
||||||
unless ARGV[0] == 'benchmark'
|
|
||||||
|
|
||||||
# ----- Default: Testing ------
|
# ----- Default: Testing ------
|
||||||
|
|
||||||
desc 'Default: run unit tests.'
|
desc 'Default: run unit tests.'
|
||||||
|
@ -160,5 +151,3 @@ END
|
||||||
|
|
||||||
puts '-'*51
|
puts '-'*51
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
|
||||||
|
|
|
@ -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
|
# There's a bizarre error where ActionController tries to load a benchmark file
|
||||||
# and ends up finding this.
|
# and ends up finding this.
|
||||||
# These declarations then cause it to break.
|
# 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"
|
raise "The Haml benchmarks require the benchwarmer gem, available from http://github.com/wycats/benchwarmer"
|
||||||
end
|
end
|
||||||
|
|
||||||
module Haml
|
Benchmark.warmer(times) do
|
||||||
# Benchmarks Haml against ERB, Erubis, and Markaby and Sass on its own.
|
|
||||||
def self.benchmark(runs = 100)
|
|
||||||
Benchmark.warmer(runs) do
|
|
||||||
columns :haml, :erb, :erubis, :mab
|
columns :haml, :erb, :erubis, :mab
|
||||||
titles :haml => "Haml", :erb => "ERB", :erubis => "Erubis", :mab => "Markaby"
|
titles :haml => "Haml", :erb => "ERB", :erubis => "Erubis", :mab => "Markaby"
|
||||||
|
|
||||||
|
@ -79,10 +89,8 @@ module Haml
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
Benchmark.warmer(runs) do
|
Benchmark.warmer(times) do
|
||||||
sass_template = File.read("#{File.dirname(__FILE__)}/sass/templates/complex.sass")
|
sass_template = File.read("#{File.dirname(__FILE__)}/sass/templates/complex.sass")
|
||||||
|
|
||||||
report("Sass") { Sass::Engine.new(sass_template).render }
|
report("Sass") { Sass::Engine.new(sass_template).render }
|
||||||
end
|
end
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
Loading…
Reference in New Issue