Skip to content

Commit c6ddd9c

Browse files
authored
Merge pull request #48 from r-devulap/temp
Add scripts to help run benchmarks
2 parents 85fbe7d + 362ad07 commit c6ddd9c

File tree

4 files changed

+57
-6
lines changed

4 files changed

+57
-6
lines changed

.github/workflows/c-cpp.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,4 @@ jobs:
9494
env:
9595
CXX: g++-12
9696
GBENCH: ${{ github.workspace }}/benchmark
97-
run: bash -x bench-compare.sh
97+
run: bash -x scripts/branch-compare.sh avx

run-bench.py

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import sys
2+
import argparse
3+
import subprocess
4+
5+
parser = argparse.ArgumentParser()
6+
parser.add_argument('--branchcompare', action='store_true', help='Compare benchmarks of current branch with main. Provide an optional --filter')
7+
parser.add_argument('--benchcompare', action='store_true', help='Compare across benchmarks. Requires --baseline and --contender')
8+
parser.add_argument("-f", '--filter', type=str, required=False)
9+
parser.add_argument("-b", '--baseline', type=str, required=False)
10+
parser.add_argument("-c", '--contender', type=str, required=False)
11+
args = parser.parse_args()
12+
13+
if len(sys.argv) == 1:
14+
parser.error("requires one of --benchcompare or --branchcompare")
15+
16+
if args.benchcompare:
17+
if (args.baseline is None or args.contender is None):
18+
parser.error("--benchcompare requires --baseline and --contender")
19+
else:
20+
rc = subprocess.check_call("./scripts/bench-compare.sh '%s %s'" % (args.baseline, args.contender), shell=True)
21+
22+
if args.branchcompare:
23+
if args.filter is None:
24+
rc = subprocess.call("./scripts/branch-compare.sh")
25+
else:
26+
rc = subprocess.check_call("./scripts/branch-compare.sh '%s'" % args.filter, shell=True)

scripts/bench-compare.sh

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/bash
2+
set -e
3+
branch=$(git rev-parse --abbrev-ref HEAD)
4+
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
5+
cd $SCRIPT_DIR/..
6+
if [[ -z "${GBENCH}" ]]; then
7+
echo "Please set env variable GBENCH and re run"
8+
exit 1
9+
fi
10+
11+
compare=$GBENCH/tools/compare.py
12+
if [ ! -f $compare ]; then
13+
echo "Unable to locate $GBENCH/tools/compare.py"
14+
exit 1
15+
fi
16+
17+
meson setup --warnlevel 0 --buildtype plain builddir-${branch}
18+
cd builddir-${branch}
19+
ninja
20+
$compare filters ./benchexe $1 $2

bench-compare.sh renamed to scripts/branch-compare.sh

+10-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
#~/bin/bash
1+
#!/bin/bash
22
set -e
33
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
4-
cd $SCRIPT_DIR
4+
BASE_DIR=$(dirname $SCRIPT_DIR)
55
branch=$(git rev-parse --abbrev-ref HEAD)
66
echo "Comparing main branch with $branch"
77

@@ -20,7 +20,7 @@ rm -rf .bench-compare
2020
mkdir .bench-compare
2121
cd .bench-compare
2222
echo "Fetching and build $branch .."
23-
git clone ${SCRIPT_DIR} -b $branch .
23+
git clone ${BASE_DIR} -b $branch .
2424
git fetch origin
2525
meson setup --warnlevel 0 --buildtype plain builddir-${branch}
2626
cd builddir-${branch}
@@ -34,5 +34,10 @@ meson setup --warnlevel 0 --buildtype plain builddir-main
3434
cd builddir-main
3535
ninja
3636
cd ..
37-
echo "Running benchmarks .."
38-
$compare benchmarks ./builddir-main/benchexe ./builddir-${branch}/benchexe
37+
if [ -z "$1" ]; then
38+
echo "Comparing all benchmarks .."
39+
$compare benchmarks ./builddir-main/benchexe ./builddir-${branch}/benchexe
40+
else
41+
echo "Comparing benchmark $1 .."
42+
$compare benchmarksfiltered ./builddir-main/benchexe $1 ./builddir-${branch}/benchexe $1
43+
fi

0 commit comments

Comments
 (0)