Skip to content

Commit

Permalink
Add benchmark time unit option to pytest_benchmark plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
tony92151 authored and ionelmc committed Oct 27, 2024
1 parent 7c05d50 commit dfbb285
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/pytest_benchmark/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,12 @@ def pytest_addoption(parser):
" Argument is a column to sort by. Available columns: 'ncalls_recursion',"
" 'ncalls', 'tottime', 'tottime_per', 'cumtime', 'cumtime_per', 'function_name'.",
)
group.addoption(
"--benchmark-time-unit",
metavar="COLUMN", default=None,
choices=['ns', 'us', 'ms', 's', 'auto'],
help="Unit to scale the results to. Available units: 'ns', 'us', 'ms', 's'. Default: 'auto'."
)
add_global_options(group.addoption)
add_display_options(group.addoption)
add_histogram_options(group.addoption)
Expand Down Expand Up @@ -367,8 +373,8 @@ def get_cpu_info():


def pytest_benchmark_scale_unit(config, unit, benchmarks, best, worst, sort):
if not config.getoption("benchmark_time_unit", None):
config_time_unit = config.getoption("benchmark_time_unit") != "ns"
if config.getoption("benchmark_time_unit", None):
config_time_unit = config.getoption("benchmark_time_unit")
if config_time_unit == "ns":
return "n", 1e9
elif config_time_unit == "us":
Expand Down

0 comments on commit dfbb285

Please sign in to comment.