1 #!/usr/bin/env python 2 """ 3 compare_bench.py - Compare two benchmarks or their results and report the 4 difference. 5 """ 6 import sys 7 import gbench 8 from gbench import util, report 9 10 def main(): 11 # Parse the command line flags 12 def usage(): 13 print('compare_bench.py <test1> <test2> [benchmark options]...') 14 exit(1) 15 if '--help' in sys.argv or len(sys.argv) < 3: 16 usage() 17 tests = sys.argv[1:3] 18 bench_opts = sys.argv[3:] 19 bench_opts = list(bench_opts) 20 # Run the benchmarks and report the results 21 json1 = gbench.util.run_or_load_benchmark(tests[0], bench_opts) 22 json2 = gbench.util.run_or_load_benchmark(tests[1], bench_opts) 23 output_lines = gbench.report.generate_difference_report(json1, json2) 24 print 'Comparing %s to %s' % (tests[0], tests[1]) 25 for ln in output_lines: 26 print(ln) 27 28 29 if __name__ == '__main__': 30 main() 31