-
Notifications
You must be signed in to change notification settings - Fork 171
/
benchmark.rb
executable file
·56 lines (46 loc) · 1.27 KB
/
benchmark.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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
#! /usr/bin/env ruby
require 'optparse'
require 'tempfile'
options = {
before: 'master',
after: 'HEAD',
bench_time: '1s'
}
OptionParser.new do |opts|
opts.banner = 'Runs benchmarks on two branches and compares the results'
opts.on('-b hash', '--before hash') do |v|
options[:before] = v
end
opts.on('-a hash', '--after hash') do |v|
options[:after] = v
end
opts.on('-t time', '--bench_time time') do |v|
options[:bench_time] = v
end
end.parse!
benchmark_options = "-run '^$' -bench '.' -benchmem -benchtime #{options[:bench_time]}"
return_to = `git rev-parse --abbrev-ref HEAD`
before_hash = `git rev-parse #{options[:before]}`.strip
after_hash = `git rev-parse #{options[:after]}`.strip
bf = Tempfile.new('before')
af = Tempfile.new('after')
begin
`git checkout #{before_hash} 2>&1`
puts "benchmarking #{before_hash}"
bf.write `go test #{benchmark_options} ./...`
`git checkout #{after_hash} 2>&1`
puts "benchmarking #{after_hash}"
af.write `go test #{benchmark_options} ./...`
af.close
bf.close
`go get golang.org/x/tools/cmd/benchcmp`
comparison = `$GOPATH/bin/benchcmp #{bf.path} #{af.path}`
puts RUBY_PLATFORM
puts comparison
rescue StandardError => e
puts e
ensure
bf.unlink
af.unlink
`git checkout #{return_to} 2>&1`
end