File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ #! /usr/bin/env bash
2+ # Usage: bench.sh V1_BIN V2_BIN HYPERFINE LIBGIT2_DIR OUT_DIR
3+ # Same setup as cpp-linter-rs#476: libgit2 v1.8.1, 133 .c files under src/libgit2, clang 18.
4+ set -u
5+ V1=$1 ; V2=$2 ; HF=$3 ; SRC=$4 ; OUT=$5 ; HERE=$( cd " $( dirname " $0 " ) " && pwd)
6+ mkdir -p " $OUT " ; cd " $SRC " ; unset GITHUB_TOKEN GITHUB_ACTIONS CI
7+ ARGS=" -l 0 -f 0 -a 0 -i=|!src/libgit2 -p build -e c -V 18"
8+ FMT=" --tidy-checks=-*"
9+ hf () { name=$1 ; shift ; " $HF " -N --style basic --export-json " $OUT /$name .json" --export-markdown " $OUT /$name .md" " $@ " > " $OUT /$name .log" 2>&1 ; }
10+ hf startup --warmup 3 --runs 20 -n v1 " $V1 version" -n v2 " $V2 version"
11+ hf format-1 --warmup 1 --runs 5 -n v1 " $V1 $ARGS $FMT -j 1" -n v2 " env TOKIO_WORKER_THREADS=1 $V2 $ARGS $FMT "
12+ hf format-all --warmup 1 --runs 5 -n v1 " $V1 $ARGS $FMT -j 0" -n v2 " $V2 $ARGS $FMT "
13+ # One run each to check that both report the same counts, and to sample peak memory.
14+ python3 " $HERE /mem.py" " $OUT /full-v1.out" $V1 $ARGS -j 0 2> " $OUT /mem-v1.txt"
15+ python3 " $HERE /mem.py" " $OUT /full-v2.out" $V2 $ARGS 2> " $OUT /mem-v2.txt"
16+ hf full-all --runs 3 -n v1 " $V1 $ARGS -j 0" -n v2 " $V2 $ARGS "
17+ hf full-1 --runs 2 -n v1 " $V1 $ARGS -j 1" -n v2 " env TOKIO_WORKER_THREADS=1 $V2 $ARGS "
18+ echo DONE > " $OUT /DONE"
Original file line number Diff line number Diff line change 1+ """Run a command, sample its own peak RSS (VmHWM), print 'peak_mib=N' to stderr."""
2+ import subprocess , sys , time
3+ log = open (sys .argv [1 ], "w" )
4+ p = subprocess .Popen (sys .argv [2 :], stdout = log , stderr = subprocess .STDOUT )
5+ hwm = 0
6+ while True :
7+ try :
8+ with open (f"/proc/{ p .pid } /status" ) as f :
9+ for line in f :
10+ if line .startswith ("VmHWM:" ):
11+ hwm = max (hwm , int (line .split ()[1 ]))
12+ except OSError :
13+ pass
14+ if p .poll () is not None :
15+ break
16+ time .sleep (0.02 )
17+ print (f"peak_mib={ hwm / 1024 :.0f} exit={ p .returncode } " , file = sys .stderr )
Original file line number Diff line number Diff line change 1+ # Benchmark for cpp-linter-rs#476: v1 (1.16.1) vs v2 (2.0.0-rc.27) on libgit2 v1.8.1.
2+ name : benchmark v1 vs v2
3+
4+ on :
5+ push :
6+ branches : [claude/project-thread-u751ea-bench]
7+
8+ permissions :
9+ contents : read
10+
11+ jobs :
12+ bench :
13+ runs-on : ubuntu-24.04
14+ timeout-minutes : 150
15+ steps :
16+ - uses : actions/checkout@v7
17+ with :
18+ persist-credentials : false
19+
20+ - name : Install tools
21+ run : |
22+ sudo apt-get update -q && sudo apt-get install -y -q clang-tidy-18 clang-format-18
23+ curl -sSL https://github.com/sharkdp/hyperfine/releases/download/v1.19.0/hyperfine-v1.19.0-x86_64-unknown-linux-musl.tar.gz | tar -xz -C "$RUNNER_TEMP"
24+ python3 -m venv "$RUNNER_TEMP/v1" && "$RUNNER_TEMP/v1/bin/pip" install -q cpp-linter==1.16.1
25+ mkdir -p "$RUNNER_TEMP/v2"
26+ curl -sSL https://github.com/cpp-linter/cpp-linter-rs/releases/download/cpp-linter/v2.0.0-rc.27/cpp-linter-x86_64-unknown-linux-gnu.tar.gz | tar -xz -C "$RUNNER_TEMP/v2"
27+ "$RUNNER_TEMP/v2/cpp-linter" version
28+ nproc; free -m
29+
30+ - name : Prepare libgit2
31+ run : |
32+ git clone -q --depth 1 --branch v1.8.1 https://github.com/libgit2/libgit2 "$RUNNER_TEMP/libgit2"
33+ cmake -B "$RUNNER_TEMP/libgit2/build" -S "$RUNNER_TEMP/libgit2" -D CMAKE_EXPORT_COMPILE_COMMANDS=ON -D BUILD_TESTS=OFF -D BUILD_CLI=OFF > /dev/null
34+
35+ - name : Benchmark
36+ run : >-
37+ .github/bench/bench.sh
38+ "$RUNNER_TEMP/v1/bin/cpp-linter"
39+ "$RUNNER_TEMP/v2/cpp-linter"
40+ "$RUNNER_TEMP/hyperfine-v1.19.0-x86_64-unknown-linux-musl/hyperfine"
41+ "$RUNNER_TEMP/libgit2"
42+ "$RUNNER_TEMP/out"
43+
44+ - name : Results
45+ if : always()
46+ run : |
47+ cd "$RUNNER_TEMP/out"
48+ for f in startup format-1 format-all full-all full-1; do echo "### $f"; cat "$f.md" 2>/dev/null; echo; done | tee -a "$GITHUB_STEP_SUMMARY"
49+ cat mem-v1.txt mem-v2.txt
50+ grep -ohE '[0-9]+ clang-(format|tidy)-checks-failed' full-v1.out | tail -2
51+ grep -ohE 'clang-(format|tidy)-checks-failed: [0-9]+' full-v2.out | tail -2
52+
53+ - uses : actions/upload-artifact@v6
54+ if : always()
55+ with :
56+ name : bench-results
57+ path : ${{ runner.temp }}/out
You can’t perform that action at this time.
0 commit comments