Skip to content

Commit

Permalink
tests/benchmark.sh: added a benchmark script for build and execution …
Browse files Browse the repository at this point in the history
…performance
  • Loading branch information
giuliomoro committed Jan 11, 2022
1 parent 2ab7f87 commit befef9c
Showing 1 changed file with 95 additions and 0 deletions.
95 changes: 95 additions & 0 deletions resources/tests/benchmark.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
#!/bin/bash -e

EXAMPLES=(
Instruments/airharp
PureData/hello-sound
Audio/telephone-filter
Analog/analog-output
Fundamentals/sinetone
Salt/pink-trombone
)
PROJECTS=() # automatically populated below

SETUP=0
BUILD=0
RUN=0

while [ -n "$1" ]
do
case $1 in
setup)
SETUP=1
;;
build)
BUILD=1
;;
run)
RUN=1
;;
*)
cat <(\
echo "usage: $0 [setup] [build] [dontrebuild] [run]"
echo " default: \`$0 setup build run'"
echo " if one or more of setup, build or run are specified, the others are disabled unless explicitly enabled"
echo " setup: initialise projects in projects/bc_* from examples"
echo " build: benchmark build of projects (by force rebuilding)"
echo " run: benchmark run"
) >&2
exit 1;
;;
esac
shift;
done

if [ 0 -eq $SETUP -a 0 -eq $BUILD -a 0 -eq $RUN ]; then
SETUP=1
BUILD=1
RUN=1
fi

for e in ${EXAMPLES[@]}; do
PROJECTS+=(bc_$(echo $e | sed s:/:-:))
done

for (( n=0; n<${#EXAMPLES[@]}; n++ )); do
e=${EXAMPLES[$n]}
p=${PROJECTS[$n]}
if [ $SETUP -eq 1 -o ! -d projects/$p ]; then
mkdir -p projects/$p
rsync -ac examples/$e/* projects/$p/
fi
done

if [ 1 -eq $BUILD ]; then
echo "========build========"
# ensure everything else is built before we go ahead and time the project build
make lib > /dev/null
make PROJECT=${PROJECTS[0]} build/core/default_libpd_render.o build/core/default_main.o > /dev/null
for p in "${PROJECTS[@]}"; do
if [ $BUILD -eq 1 ]; then
make PROJECT=$p clean > /dev/null
srcs=$(ls $PWD/projects/$p/*.cpp 2> /dev/null || true)
objs=$(\
for a in $srcs; do
printf "$a " | sed "s \(projects/$p\)/\(.*\).cpp \1/build/\2.o g"
done
)
# annoyingly to get the output of `time` one needs to eval it
if [ -n "$objs" ]; then
eval "time make PROJECT=$p $objs" 2>&1 | grep real | sed 's/real[ \t]*//' | cat <(printf "$p compile: ") -
fi
eval "time make PROJECT=$p" 2>&1 | grep real | sed 's/real[ \t]*//' | cat <(printf "$p link: ") -
fi
done
fi

if [ 1 -eq $RUN ]; then
echo "========run========"
for p in ${PROJECTS[@]}; do
printf "building $p\r"
make PROJECT=$p > /dev/null
printf "$(tput el)"
printf "$p: "
make PROJECT=$p CL='--board=Batch --codec-mode="s=1,p=95,t=2"' run | grep cpu:
done
fi

0 comments on commit befef9c

Please sign in to comment.