Permalink
Browse files

Ability to run command before benchmark

  • Loading branch information...
bogdan committed Sep 3, 2012
1 parent f628547 commit 034de11843a28ba56dacf2552cb3e5c9338de7d6
Showing with 18 additions and 5 deletions.
  1. +11 −3 lib/diffbench.rb
  2. +7 −2 spec/diffbench_spec.rb
View
@@ -21,11 +21,15 @@ def initialize(*args)
DOC
opts.on("-r", '--revision [REVISIONS]', 'Specify revisions to run benchmark (comma separated). Example: master,f9a845,v3.1.4') do |value|
- #if tree_dirty?
- #raise Error, "Working tree is dirty."
- #end
+ if tree_dirty?
+ raise Error, "Working tree is dirty."
+ end
@revisions = value.split(",")
end
+ opts.on("-b", '--before [COMMAND]', 'Specify command to run before each benchmark run. e.g. bundle install') do |value|
+ @before_command = value
+ end
+
opts.on_tail('--help', 'Show this help') do
output opts
@@ -51,6 +55,7 @@ def run_revisions
@revisions.inject({}) do |result, revision|
output "Checkout to #{revision}"
output "Run benchmark with #{revision}"
+ git_run("checkout '#{revision}'")
result[revision] = run_file
result
end
@@ -59,6 +64,7 @@ def run_revisions
git_run("checkout '#{branch}'")
end
output ""
+ #TODO set caption the right way
caption = "Before patch: ".gsub(/./, " ") + Benchmark::Tms::CAPTION
output caption
tests = results.values.first.keys
@@ -67,6 +73,7 @@ def run_revisions
results.each do |revision, benchmark|
output "#{revision}: #{benchmark[test].format}"
end
+ #TODO set improvement
#improvement = improvement_percentage(before_patch, after_patch)
#color_string = result_color(improvement)
#output self.class.color("Improvement: #{improvement}%", color_string).strip
@@ -150,6 +157,7 @@ def current_head
end
def run_file
+ output `#{@before_command}` if @before_command
output = `ruby -I#{File.dirname(__FILE__)} #{@file}`
output.split("\n").select! do |line|
if line.start_with?("diffbench:")
View
@@ -55,6 +55,11 @@ def to_regexp(output)
OUT
end
+ it "should suppor before command option" do
+ output = `cd #{repo}; ./../../bin/diffbench -b "echo hello" bench.rb`
+ output.should include("hello")
+ end
+
describe "when changes got commit" do
before(:each) do
@@ -104,11 +109,11 @@ def to_regexp(output)
user system total real
--------------------------------------------------Sleeper 1
#{revs.first}: 0.000000 0.000000 0.000000 ( 0.100NUM)
-#{revs.last }: 0.000000 0.000000 0.000000 ( 0.100NUM)
+#{revs.last }: 0.000000 0.000000 0.000000 ( 0.200NUM)
--------------------------------------------------Sleeper 2
#{revs.first}: 0.000000 0.000000 0.000000 ( 0.100NUM)
-#{revs.last }: 0.000000 0.000000 0.000000 ( 0.100NUM)
+#{revs.last }: 0.000000 0.000000 0.000000 ( 0.200NUM)
OUT
end
end

0 comments on commit 034de11

Please sign in to comment.