Skip to content

Instantly share code, notes, and snippets.

@bmabey
Created January 14, 2009 20:03
Show Gist options
  • Save bmabey/47040 to your computer and use it in GitHub Desktop.
Save bmabey/47040 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
spec_commands = {"1.1.12" => "spec", "#does_not_match? version" => "~/p/ruby/rspec/bin/spec"}
base_line = "1.1.12"
number_of_runs = ENV['NUMBER_OF_RUNS'] || 50
class Array
def average
@average ||= self.inject{|sum,v| sum + v} / size.to_f
end
end
run_results = {}
totals = {}
spec_commands.each do |version, bin|
command = "#{bin} #{ARGV.join(' ')}"
puts "Running the spec #{version} #{number_of_runs} times: #{command}"
run_results[version] = []
number_of_runs.times do |i|
print "."
STDOUT.flush
`#{command}` =~ /Finished in (.+) seconds/
run_results[version] << $1.to_f
end
puts ""
end
puts "Average Run Time"
spec_commands.each do |version, _|
min, max = [run_results[base_line].average, run_results[version].average].sort
percentage = ((max - min) / min) * 100.0
diff = (min == run_results[version].average) ? "faster" : "slower"
puts "#{version} - #{run_results[version].average} seconds (#{percentage}% #{diff} than #{base_line})"
end
describe "Truth" do
5000.times do |i|
it "should not be false" do
true.should_not be_false
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment