21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
# File 'lib/diffbench.rb', line 21
def run
output "Running benchmark with current working tree"
first_run = run_file
if tree_dirty?
output "Stashing changes"
git_run "stash"
output "Running benchmark with clean working tree"
begin
second_run = run_file
ensure
output "Applying stashed changes back"
git_run "stash pop"
end
elsif branch = current_head
output "Checkout HEAD^"
git_run "checkout 'HEAD^'"
output "Running benchmark with HEAD^"
begin
second_run = run_file
ensure
output "Checkout to previous HEAD again"
git_run "checkout #{branch}"
end
else
raise Error, "No current branch."
end
output ""
caption = "Before patch: ".gsub(/./, " ") + Benchmark::Tms::CAPTION
output caption
first_run.keys.each do |test|
output ("-"* (caption.size - test.size)) + test
before_patch = second_run[test]
after_patch = first_run[test]
improvement = improvement_percentage(before_patch, after_patch)
color_string = result_color(improvement)
output "After patch: #{after_patch.format}"
output "Before patch: #{before_patch.format}"
if color_string
output self.class.color("Improvement: #{improvement}%", color_string).strip
end
output ""
end
end
|