-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make benchmarks run on multiple branches without conflicts
- copy target files to a temp directory - benchmark cache/no cache on each branch - compare branches - remove rake dependency that loads unnecessary files - run with ./bin/bench - remove git gem dependency Master looks slower than some older refs; need to confirm
- Loading branch information
Showing
5 changed files
with
242 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,5 +46,4 @@ end | |
|
||
group :development, :test do | ||
gem 'rubocop', '~> 0.34.0', require: false | ||
gem 'git' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
#!/usr/bin/env ruby | ||
require 'fileutils' | ||
require 'benchmark' | ||
require 'pathname' | ||
require 'shellwords' | ||
|
||
ROOT = Pathname File.expand_path(['..', '..'].join(File::Separator), __FILE__) | ||
TMP_DIR = File.join(ROOT, 'tmp/bench') | ||
|
||
def temp_dir_empty? | ||
Dir[File.join(TMP_DIR, '*')].none? | ||
end | ||
|
||
def empty_temp_dir | ||
FileUtils.mkdir_p(TMP_DIR) | ||
Dir[File.join(TMP_DIR, '*')].each do |file| | ||
FileUtils.rm(file) | ||
end | ||
end | ||
|
||
def fill_temp_dir | ||
Dir[File.join(ROOT, 'test', '**', '*_benchmark.rb')].each do |file| | ||
FileUtils.cp(file, File.join(TMP_DIR, File.basename(file))) | ||
end | ||
at_exit { empty_temp_dir } | ||
end | ||
|
||
def refresh_temp_dir | ||
empty_temp_dir | ||
fill_temp_dir | ||
end | ||
|
||
def benchmark_tests | ||
refresh_temp_dir if temp_dir_empty? | ||
system("bundle exec ruby -Ilib:test #{Shellwords.shellescape(TMP_DIR)}/*.rb") | ||
end | ||
|
||
def current_branch | ||
@current_branch ||= `cat .git/HEAD | cut -d/ -f3,4,5`.chomp | ||
end | ||
|
||
def checkout_ref(ref) | ||
puts `git checkout #{ref}`.chomp | ||
abort "Checkout failed: #{ref}, #{$?.exitstatus}" unless $?.success? | ||
end | ||
|
||
def benchmark | ||
refresh_temp_dir | ||
ref = current_branch | ||
|
||
actual = run_benchmark_at_ref ref | ||
master = run_benchmark_at_ref 'master' | ||
|
||
checkout_ref(ref) | ||
|
||
puts "\n\nResults ============================\n" | ||
puts "------------------------------------~> (Branch) MASTER" | ||
puts master | ||
puts "------------------------------------\n\n" | ||
|
||
puts "------------------------------------~> (Actual Branch) #{ref}" | ||
puts actual | ||
puts "------------------------------------" | ||
end | ||
|
||
def run_benchmark | ||
response = Benchmark.realtime { | ||
benchmark_tests | ||
} | ||
benchmark_tests | ||
response | ||
end | ||
|
||
def run_benchmark_at_ref(ref) | ||
checkout_ref(ref) | ||
run_benchmark | ||
end | ||
|
||
if $0 == __FILE__ | ||
benchmark | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters