make bench smart; don't assume input/output ports

This commit is contained in:
Connor Olding 2013-11-16 11:51:01 -08:00
parent 2dc7487a90
commit d609b1f687
4 changed files with 27 additions and 7 deletions

View File

@ -30,6 +30,9 @@ all: options ${ALL}
bench: all ${BENCH}
@echo LD ${BENCH} ${MID} -o $@
@${CC} ${ALL_CFLAGS} ${BENCH} -o $@ ${ALL_LDFLAGS} -rdynamic -ldl
.PHONY: benchmark
benchmark: bench
./benchtime ./bench ${AGAINST}
.PHONY: options

View File

@ -21,7 +21,7 @@ white noise generator. loud, full-range, 0dBFS. don't say i didn't warn you.
## build notes
`make` it. optional `bench` benchmarking target, doesn't build on Windows.
`make` it. optional `benchmark` target which doesn't build on Windows.
if you're using gcc, try `CFLAGS='-O3 -ffast-math'`.
`-march=native` actually seems to degrade performance slightly, but YMMV.

23
bench.c
View File

@ -1,4 +1,5 @@
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#include <time.h>
@ -10,13 +11,14 @@ enum {
BLOCK_SIZE=2048
};
float inputs[BLOCK_SIZE];
float outputs[BLOCK_SIZE];
void *plug = NULL;
static float *audio_buffer;
static int audio_count = 0;
static void
cleanup() {
dlclose(plug);
if (audio_count) free(audio_buffer);
}
static const LADSPA_Descriptor*
@ -43,12 +45,21 @@ main(int argc, char **argv) {
LADSPA_Handle h = d->instantiate(d, 44100);
assert(h);
d->connect_port(h, 0, inputs);
d->connect_port(h, 1, outputs);
// we're lazy so we don't distinguish inputs and outputs
for (int i = 0; i < d->PortCount; i++)
if (LADSPA_IS_PORT_AUDIO(d->PortDescriptors[i]))
audio_count++;
audio_buffer = calloc(audio_count*BLOCK_SIZE, sizeof(float));
int a = 0;
for (int i = 0; i < d->PortCount; i++)
if (LADSPA_IS_PORT_AUDIO(d->PortDescriptors[i]))
d->connect_port(h, i, audio_buffer + a++*BLOCK_SIZE);
mirand = time(NULL);
for (int i = 0; i < BLOCK_SIZE; i++)
inputs[i] = whitenoise();
for (int i = 0; i < audio_count*BLOCK_SIZE; i++)
audio_buffer[i] = whitenoise();
if (d->activate) d->activate(h);
for (int i = 0; i < 64*64*8; i++)

View File

@ -2,6 +2,12 @@
bench="$1"
against="$2"
cleanup() {
echo -e "\e[0;"
exit 0
}
trap cleanup INT
TIMEFORMAT='%3R'
for i in {1..8}; do
time "$bench" "$against"