SHARE
TWEET

Untitled

a guest Apr 16th, 2017 26 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env python3
  2.  
  3. import subprocess as subp
  4. import git
  5.  
  6. repo_path = '/home/redacted/factorio/mystuff/moddev/reactors-performance/Reactors_1.6.0'
  7.  
  8. def benchmark_current_code():
  9.     bench_output = subp.check_output(['./run_benchmark.bash'],
  10.                                      universal_newlines=True,
  11.                                      stderr=subp.DEVNULL)
  12.     summary_line = bench_output.splitlines()[-1]
  13.     summary_split = summary_line.split()
  14.     result={
  15.             'avg' : float(summary_split[1]),
  16.             'min' : float(summary_split[4]),
  17.             'max' : float(summary_split[7])
  18.             }
  19.     assert result['min'] <= result['avg']
  20.     assert result['avg'] <= result['max']
  21.     return result
  22.  
  23. def best_of_n_benchmarks(n):
  24.     benches = [benchmark_current_code() for i in range(n)]
  25.     best_avg = 1e9
  26.     for bench in benches:
  27.         if bench['avg'] < best_avg:
  28.             best = bench
  29.     return best
  30.  
  31. def print_table_line(commit, bench_result):
  32.     short_message = commit.message.splitlines()[0]
  33.     line = "{}  {:6.2f}  {:6.2f}  {:6.2f}  {}".format(
  34.             commit.hexsha[:7],
  35.             bench_result['avg'],
  36.             bench_result['min'],
  37.             bench_result['max'],
  38.             short_message)
  39.     print(line)
  40.  
  41. def main():
  42.     repo = git.Repo(repo_path)
  43.     print('Commit   avg ms  min ms  max ms  Message')
  44.     for commit in repo.iter_commits('master', max_count=5):
  45.         #checkout
  46.         repo.git.checkout(commit.hexsha)
  47.         print_table_line(commit, best_of_n_benchmarks(5))
  48.     repo.git.checkout('master')
  49.  
  50. if __name__ == '__main__':
  51.     main()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top