Skip to content

Commit

Permalink
Merge pull request #659 from eliothedeman/update-benchmars
Browse files Browse the repository at this point in the history
rework benchmark running
  • Loading branch information
st0012 authored Apr 30, 2018
2 parents 2fd6637 + a713e4b commit b6a1996
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 46 deletions.
13 changes: 0 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ GOFMT ?= gofmt -s
GOFILES := $(shell find . -name "*.go" -type f -not -path "./vendor/*")
RELEASE_OPTIONS := -ldflags "-s -w -X github.com/goby-lang/goby/vm.DefaultLibPath=${GOBY_LIBPATH}" -tags release
TEST_OPTIONS := -ldflags "-s -w"
BENCHMARK_OPTIONS := -run '^$$' -bench '.' -benchmem -benchtime 2s

.PHONY: fmt
fmt:
Expand All @@ -23,15 +22,3 @@ test:
.PHONY: clean
clean:
go clean .

.PHONY: update_benchmarks
update_benchmarks:
go test $(BENCHMARK_OPTIONS) ./... > current_benchmarks

.PHONY: compare_benchmarks
compare_benchmarks:
go test $(BENCHMARK_OPTIONS) ./... > .tmp_benchmarks
benchcmp current_benchmarks .tmp_benchmarks



56 changes: 56 additions & 0 deletions benchmark.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,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
33 changes: 0 additions & 33 deletions current_benchmarks

This file was deleted.

0 comments on commit b6a1996

Please sign in to comment.