benchmark.py 692 B

12345678910111213141516171819202122
  1. import json
  2. from . import process
  3. from . import runtime
  4. def execute_benchmark(path, budget=None, threads=None):
  5. """
  6. Run benchmark and return values
  7. :param path: path to benchmark binary
  8. :param budget: time budget, sec (supported only by ybenchmark)
  9. :param threads: number of threads to run benchmark (supported only by ybenchmark)
  10. :return: map of benchmark values
  11. """
  12. benchmark_path = runtime.binary_path(path)
  13. cmd = [benchmark_path, "--benchmark_format=json"]
  14. if budget is not None:
  15. cmd += ["-b", str(budget)]
  16. if threads is not None:
  17. cmd += ["-t", str(threads)]
  18. res = process.execute(cmd)
  19. return json.loads(res.std_out)