Skip to content

Commit 921eb85

Browse files
committed
Add JSON output option for NumPy benchmark report
1 parent 43bf70c commit 921eb85

2 files changed

Lines changed: 10 additions & 0 deletions

File tree

benchmark/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ set(XTENSOR_NUMPY_BENCHMARK_CFLAGS "${_xtensor_numpy_benchmark_cflags}" CACHE ST
7272
set(XTENSOR_NUMPY_BENCHMARK_BLAS "openblas" CACHE STRING "BLAS backend requested when building NumPy from source for comparison benchmarks")
7373
set(XTENSOR_NUMPY_BENCHMARK_LAPACK "openblas" CACHE STRING "LAPACK backend requested when building NumPy from source for comparison benchmarks")
7474
set(XTENSOR_NUMPY_BENCHMARK_REPORT "${CMAKE_BINARY_DIR}/xtensor_numpy_report.md" CACHE FILEPATH "Output path for the xtensor vs NumPy benchmark report")
75+
set(XTENSOR_NUMPY_BENCHMARK_REPORT_JSON "${CMAKE_BINARY_DIR}/xtensor_numpy_report.json" CACHE FILEPATH "Output path for the raw Google Benchmark JSON used by the xtensor vs NumPy benchmark report")
7576
set(XTENSOR_NUMPY_BENCHMARK_REPORT_FILTER ".*_(xtensor|numpy)/.*" CACHE STRING "Google Benchmark filter used when generating the xtensor vs NumPy report")
7677
set(XTENSOR_NUMPY_BENCHMARK_REPORT_MIN_TIME "0.05s" CACHE STRING "Minimum benchmark runtime used when generating the xtensor vs NumPy report")
7778

@@ -164,6 +165,7 @@ if(BUILD_NUMPY_BENCHMARKS)
164165
--benchmark-exe $<TARGET_FILE:${XTENSOR_BENCHMARK_TARGET}>
165166
--benchmark-filter=${XTENSOR_NUMPY_BENCHMARK_REPORT_FILTER}
166167
--benchmark-min-time=${XTENSOR_NUMPY_BENCHMARK_REPORT_MIN_TIME}
168+
--output-json ${XTENSOR_NUMPY_BENCHMARK_REPORT_JSON}
167169
--output ${XTENSOR_NUMPY_BENCHMARK_REPORT}
168170
DEPENDS xbenchmark_numpy_env ${XTENSOR_BENCHMARK_TARGET}
169171
USES_TERMINAL

tools/report_numpy_benchmarks.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ def parse_args() -> argparse.Namespace:
3434
type=Path,
3535
help="Optional file path to write the Markdown report to.",
3636
)
37+
parser.add_argument(
38+
"--output-json",
39+
type=Path,
40+
help="Optional file path to write the raw Google Benchmark JSON used for the report.",
41+
)
3742
parser.add_argument(
3843
"--benchmark-filter",
3944
default=".*_(xtensor|numpy)/.*",
@@ -197,6 +202,9 @@ def main() -> int:
197202
else:
198203
data = run_benchmarks(args.benchmark_exe, args.benchmark_filter, args.benchmark_min_time)
199204

205+
if args.output_json is not None:
206+
args.output_json.write_text(json.dumps(data, indent=2))
207+
200208
report = render_report(data, args.metric)
201209
if args.output is not None:
202210
args.output.write_text(report)

0 commit comments

Comments
 (0)