make bench smart; don't assume input/output ports
This commit is contained in:
parent
2dc7487a90
commit
d609b1f687
4 changed files with 27 additions and 7 deletions
3
Makefile
3
Makefile
|
@ -30,6 +30,9 @@ all: options ${ALL}
|
||||||
bench: all ${BENCH}
|
bench: all ${BENCH}
|
||||||
@echo LD ${BENCH} ${MID} -o $@
|
@echo LD ${BENCH} ${MID} -o $@
|
||||||
@${CC} ${ALL_CFLAGS} ${BENCH} -o $@ ${ALL_LDFLAGS} -rdynamic -ldl
|
@${CC} ${ALL_CFLAGS} ${BENCH} -o $@ ${ALL_LDFLAGS} -rdynamic -ldl
|
||||||
|
|
||||||
|
.PHONY: benchmark
|
||||||
|
benchmark: bench
|
||||||
./benchtime ./bench ${AGAINST}
|
./benchtime ./bench ${AGAINST}
|
||||||
|
|
||||||
.PHONY: options
|
.PHONY: options
|
||||||
|
|
|
@ -21,7 +21,7 @@ white noise generator. loud, full-range, 0dBFS. don't say i didn't warn you.
|
||||||
|
|
||||||
## build notes
|
## 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'`.
|
if you're using gcc, try `CFLAGS='-O3 -ffast-math'`.
|
||||||
`-march=native` actually seems to degrade performance slightly, but YMMV.
|
`-march=native` actually seems to degrade performance slightly, but YMMV.
|
||||||
|
|
23
bench.c
23
bench.c
|
@ -1,4 +1,5 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
|
@ -10,13 +11,14 @@ enum {
|
||||||
BLOCK_SIZE=2048
|
BLOCK_SIZE=2048
|
||||||
};
|
};
|
||||||
|
|
||||||
float inputs[BLOCK_SIZE];
|
|
||||||
float outputs[BLOCK_SIZE];
|
|
||||||
void *plug = NULL;
|
void *plug = NULL;
|
||||||
|
static float *audio_buffer;
|
||||||
|
static int audio_count = 0;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
cleanup() {
|
cleanup() {
|
||||||
dlclose(plug);
|
dlclose(plug);
|
||||||
|
if (audio_count) free(audio_buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const LADSPA_Descriptor*
|
static const LADSPA_Descriptor*
|
||||||
|
@ -43,12 +45,21 @@ main(int argc, char **argv) {
|
||||||
LADSPA_Handle h = d->instantiate(d, 44100);
|
LADSPA_Handle h = d->instantiate(d, 44100);
|
||||||
assert(h);
|
assert(h);
|
||||||
|
|
||||||
d->connect_port(h, 0, inputs);
|
// we're lazy so we don't distinguish inputs and outputs
|
||||||
d->connect_port(h, 1, 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);
|
mirand = time(NULL);
|
||||||
for (int i = 0; i < BLOCK_SIZE; i++)
|
for (int i = 0; i < audio_count*BLOCK_SIZE; i++)
|
||||||
inputs[i] = whitenoise();
|
audio_buffer[i] = whitenoise();
|
||||||
|
|
||||||
if (d->activate) d->activate(h);
|
if (d->activate) d->activate(h);
|
||||||
for (int i = 0; i < 64*64*8; i++)
|
for (int i = 0; i < 64*64*8; i++)
|
||||||
|
|
|
@ -2,6 +2,12 @@
|
||||||
bench="$1"
|
bench="$1"
|
||||||
against="$2"
|
against="$2"
|
||||||
|
|
||||||
|
cleanup() {
|
||||||
|
echo -e "\e[0;"
|
||||||
|
exit 0
|
||||||
|
}
|
||||||
|
trap cleanup INT
|
||||||
|
|
||||||
TIMEFORMAT='%3R'
|
TIMEFORMAT='%3R'
|
||||||
for i in {1..8}; do
|
for i in {1..8}; do
|
||||||
time "$bench" "$against"
|
time "$bench" "$against"
|
||||||
|
|
Loading…
Reference in a new issue