From a52ed959b1b71dbd0efd082bbf7d091720d0d6bd Mon Sep 17 00:00:00 2001 From: Connor Olding Date: Mon, 11 Nov 2013 08:26:22 -0800 Subject: [PATCH] rough benchmarking stuff --- Makefile | 11 +++++++++- bench.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ bench.sh | 19 ++++++++++++++++++ 3 files changed, 90 insertions(+), 1 deletion(-) create mode 100644 bench.c create mode 100755 bench.sh diff --git a/Makefile b/Makefile index 5648fc0..0a96b47 100644 --- a/Makefile +++ b/Makefile @@ -6,6 +6,9 @@ SHOBJ = crap_eq.so crap_eq_const.so crap_noise.so MID = HEADERS = crap_util.h crap_util_def.h ladspa.h +BENCH = bench.o +AGAINST = ./crap_eq_const.so + OBJ = ${SHOBJ:.so=.o} ${EXE:=.o} ${MID} SRC = ${OBJ:.o=.c} @@ -24,6 +27,11 @@ LADSPADEST = ${DESTDIR}${LADSPADIR} all: options ${ALL} +bench: all ${BENCH} + @echo LD ${BENCH} ${MID} -o $@ + @${CC} ${ALL_CFLAGS} ${BENCH} -o $@ ${ALL_LDFLAGS} -rdynamic -ldl + ./bench.sh ./bench ${AGAINST} + .PHONY: options options: @echo "ALL_CFLAGS = ${ALL_CFLAGS}" @@ -49,12 +57,13 @@ install: all install -m 644 ${SHOBJ} ${LADSPADEST} clean: - -rm -f ${ALL} + -rm -f ${ALL} bench ${BENCH} dist: -rm -f ${FULLNAME}.tar.gz mkdir -p ${FULLNAME} cp LICENSE README.md Makefile ${HEADERS} ${SRC} ${FULLNAME} + cp bench.sh ${BENCH:.o=.c} ${FULLNAME} tar -cf ${FULLNAME}.tar ${FULLNAME} gzip ${FULLNAME}.tar rm -rf ${FULLNAME} diff --git a/bench.c b/bench.c new file mode 100644 index 0000000..e1eff39 --- /dev/null +++ b/bench.c @@ -0,0 +1,61 @@ +#include +#include +#include + +#include "dlfcn.h" +#include "ladspa.h" +#include "crap_util.h" + +enum { + BLOCK_SIZE=2048 +}; + +float inputs[BLOCK_SIZE]; +float outputs[BLOCK_SIZE]; +void *plug = NULL; + +static void +cleanup() { + dlclose(plug); +} + +static const LADSPA_Descriptor* +load_ladspa(char *path) { + plug = dlopen(path, RTLD_NOW); + assert(plug); + atexit(cleanup); + + LADSPA_Descriptor_Function df = dlsym(plug, "ladspa_descriptor"); + assert(df); + + const LADSPA_Descriptor *d = df(0); + assert(d); + + return d; +} + +int +main(int argc, char **argv) { + assert(argc > 1); + + const LADSPA_Descriptor *d = load_ladspa(argv[1]); + + LADSPA_Handle h = d->instantiate(d, 44100); + assert(h); + + d->connect_port(h, 0, inputs); + d->connect_port(h, 1, outputs); + + mirand = time(NULL); + for (int i = 0; i < BLOCK_SIZE; i++) + inputs[i] = whitenoise(); + + if (d->activate) d->activate(h); + for (int i = 0; i < 64*64*8; i++) + d->run(h, BLOCK_SIZE); + if (d->deactivate) d->deactivate(h); + + d->cleanup(h); + + return 0; +} diff --git a/bench.sh b/bench.sh new file mode 100755 index 0000000..01f5ca3 --- /dev/null +++ b/bench.sh @@ -0,0 +1,19 @@ +#!/bin/zsh +local bench="$1" +local against="$2" +local i x n=0 t m=9999 +finish() { + [ $n -gt 0 ] && printf "\nmin %.3f avg %.3f total %.3f\n" $m $((x/n)) $x + exit 0 +} +trap finish INT +echo -n "…" +for ((i=0; i<8; i++)); do + sleep 0.5 + t="$(TIMEFMT='%*E'$'\n'; (time "$bench" "$against") 2>&1)" + echo -n " ${t}" + let 'x += t' + let 'n += 1' + [[ $t < $m ]] && m=$t +done +finish