xref: /llvm-project/libcxx/utils/libcxx-compare-benchmarks (revision 8688a31729cfd2f069fc53a5081273d61803a32f)
1#!/usr/bin/env bash
2
3set -e
4
5PROGNAME="$(basename "${0}")"
6MONOREPO_ROOT="$(realpath $(dirname "${PROGNAME}"))"
7function usage() {
8cat <<EOF
9Usage:
10${PROGNAME} [-h|--help] <baseline-build> <candidate-build> benchmarks... [-- gbench-args...]
11
12Compare the given benchmarks between the baseline and the candidate build directories.
13
14This requires those benchmarks to have already been generated in both build directories.
15
16<baseline-build>     The path to the build directory considered the baseline.
17<candidate-build>    The path to the build directory considered the candidate.
18benchmarks...        Paths of the benchmarks to compare. Those paths are relative to '<monorepo-root>'.
19[-- gbench-args...]  Any arguments provided after '--' will be passed as-is to GoogleBenchmark's compare.py tool.
20
21Example
22=======
23$ libcxx-lit build1/ -sv libcxx/test/benchmarks/algorithms/for_each.bench.cpp
24$ libcxx-lit build2/ -sv libcxx/test/benchmarks/algorithms/for_each.bench.cpp
25$ ${PROGNAME} build1/ build2/ libcxx/test/benchmarks/algorithms/for_each.bench.cpp
26EOF
27}
28
29if [[ "${1}" == "-h" || "${1}" == "--help" ]]; then
30    usage
31    exit 0
32fi
33
34if [[ $# -lt 1 ]]; then
35    usage
36    exit 1
37fi
38
39baseline="${1}"
40candidate="${2}"
41shift; shift
42
43GBENCH="${MONOREPO_ROOT}/third-party/benchmark"
44
45python3 -m venv /tmp/libcxx-compare-benchmarks-venv
46source /tmp/libcxx-compare-benchmarks-venv/bin/activate
47pip3 install -r ${GBENCH}/tools/requirements.txt
48
49benchmarks=""
50while [[ $# -gt 0 ]]; do
51    if [[ "${1}" == "--" ]]; then
52        shift
53        break
54    fi
55    benchmarks+=" ${1}"
56    shift
57done
58
59for benchmark in ${benchmarks}; do
60    base="$(${MONOREPO_ROOT}/libcxx/utils/libcxx-benchmark-json ${baseline} ${benchmark})"
61    cand="$(${MONOREPO_ROOT}/libcxx/utils/libcxx-benchmark-json ${candidate} ${benchmark})"
62
63    if [[ ! -e "${base}" ]]; then
64        echo "Benchmark ${benchmark} does not exist in the baseline"
65        continue
66    fi
67    if [[ ! -e "${cand}" ]]; then
68        echo "Benchmark ${benchmark} does not exist in the candidate"
69        continue
70    fi
71
72    "${GBENCH}/tools/compare.py" benchmarks "${base}" "${cand}" ${@}
73done
74