aboutsummaryrefslogtreecommitdiffstats
path: root/library/python/testing/yatest_common/yatest/common/benchmark.py
blob: d664aa389dcf23d999dd31f4b8381e6d78fdd036 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import json

from . import process 
from . import runtime 


def execute_benchmark(path, budget=None, threads=None):
    """
    Run benchmark and return values
    :param path: path to benchmark binary
    :param budget: time budget, sec (supported only by ybenchmark)
    :param threads: number of threads to run benchmark (supported only by ybenchmark)
    :return: map of benchmark values
    """
    benchmark_path = runtime.binary_path(path)
    cmd = [benchmark_path, "--benchmark_format=json"]
    if budget is not None:
        cmd += ["-b", str(budget)]
    if threads is not None:
        cmd += ["-t", str(threads)]
    res = process.execute(cmd)
    return json.loads(res.std_out)