Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- import subprocess as subp
- import git
- repo_path = '/home/redacted/factorio/mystuff/moddev/reactors-performance/Reactors_1.6.0'
- def benchmark_current_code():
- bench_output = subp.check_output(['./run_benchmark.bash'],
- universal_newlines=True,
- stderr=subp.DEVNULL)
- summary_line = bench_output.splitlines()[-1]
- summary_split = summary_line.split()
- result={
- 'avg' : float(summary_split[1]),
- 'min' : float(summary_split[4]),
- 'max' : float(summary_split[7])
- }
- assert result['min'] <= result['avg']
- assert result['avg'] <= result['max']
- return result
- def best_of_n_benchmarks(n):
- benches = [benchmark_current_code() for i in range(n)]
- best_avg = 1e9
- for bench in benches:
- if bench['avg'] < best_avg:
- best = bench
- return best
- def print_table_line(commit, bench_result):
- short_message = commit.message.splitlines()[0]
- line = "{} {:6.2f} {:6.2f} {:6.2f} {}".format(
- commit.hexsha[:7],
- bench_result['avg'],
- bench_result['min'],
- bench_result['max'],
- short_message)
- print(line)
- def main():
- repo = git.Repo(repo_path)
- print('Commit avg ms min ms max ms Message')
- for commit in repo.iter_commits('master', max_count=5):
- #checkout
- repo.git.checkout(commit.hexsha)
- print_table_line(commit, best_of_n_benchmarks(5))
- repo.git.checkout('master')
- if __name__ == '__main__':
- main()
Add Comment
Please, Sign In to add comment