rough benchmarking stuff
This commit is contained in:
parent
a05477f429
commit
a52ed959b1
3 changed files with 90 additions and 1 deletions
11
Makefile
11
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}
|
||||
|
|
61
bench.c
Normal file
61
bench.c
Normal file
|
@ -0,0 +1,61 @@
|
|||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
#include <time.h>
|
||||
|
||||
#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;
|
||||
}
|
19
bench.sh
Executable file
19
bench.sh
Executable file
|
@ -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
|
Loading…
Reference in a new issue