Add a benchmarker for the sample converters.
This commit is contained in:
parent
cf9e3005e8
commit
bad821f5de
8
Makefile
8
Makefile
|
@ -39,7 +39,7 @@ faup1090: faup1090.o anet.o mode_ac.o mode_s.o net_io.o crc.o stats.o cpr.o icao
|
||||||
$(CC) -g -o $@ $^ $(LDFLAGS) $(LIBS)
|
$(CC) -g -o $@ $^ $(LDFLAGS) $(LIBS)
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f *.o compat/clock_gettime/*.o compat/clock_nanosleep/*.o dump1090 view1090 faup1090 cprtests crctests
|
rm -f *.o compat/clock_gettime/*.o compat/clock_nanosleep/*.o dump1090 view1090 faup1090 cprtests crctests convert_benchmark
|
||||||
|
|
||||||
test: cprtests
|
test: cprtests
|
||||||
./cprtests
|
./cprtests
|
||||||
|
@ -49,3 +49,9 @@ cprtests: cpr.o cprtests.o
|
||||||
|
|
||||||
crctests: crc.c crc.h
|
crctests: crc.c crc.h
|
||||||
$(CC) $(CPPFLAGS) $(CFLAGS) -g -DCRCDEBUG -o $@ $<
|
$(CC) $(CPPFLAGS) $(CFLAGS) -g -DCRCDEBUG -o $@ $<
|
||||||
|
|
||||||
|
benchmarks: convert_benchmark
|
||||||
|
./convert_benchmark
|
||||||
|
|
||||||
|
convert_benchmark: convert_benchmark.o convert.o util.o
|
||||||
|
$(CC) $(CPPFLAGS) $(CFLAGS) -g -o $@ $^ -lm
|
||||||
|
|
88
convert_benchmark.c
Normal file
88
convert_benchmark.c
Normal file
|
@ -0,0 +1,88 @@
|
||||||
|
#include "dump1090.h"
|
||||||
|
|
||||||
|
static uint8_t *testdata_uc8;
|
||||||
|
static uint16_t *testdata_sc16;
|
||||||
|
static uint16_t *testdata_sc16q11;
|
||||||
|
static uint16_t *outdata;
|
||||||
|
|
||||||
|
void prepare()
|
||||||
|
{
|
||||||
|
srand(1);
|
||||||
|
|
||||||
|
testdata_uc8 = calloc(MODES_MAG_BUF_SAMPLES, 2);
|
||||||
|
testdata_sc16 = calloc(MODES_MAG_BUF_SAMPLES, 4);
|
||||||
|
testdata_sc16q11 = calloc(MODES_MAG_BUF_SAMPLES, 4);
|
||||||
|
outdata = calloc(MODES_MAG_BUF_SAMPLES, sizeof(uint16_t));
|
||||||
|
|
||||||
|
for (unsigned i = 0; i < MODES_MAG_BUF_SAMPLES; ++i) {
|
||||||
|
double I = 2.0 * rand() / (RAND_MAX + 1.0) - 1.0;
|
||||||
|
double Q = 2.0 * rand() / (RAND_MAX + 1.0) - 1.0;
|
||||||
|
|
||||||
|
testdata_uc8[i*2] = (uint8_t) (I * 128 + 128);
|
||||||
|
testdata_uc8[i*2+1] = (uint8_t) (Q * 128 + 128);
|
||||||
|
|
||||||
|
testdata_sc16[i*2] = htole16( (int16_t) (I * 32768.0) );
|
||||||
|
testdata_sc16[i*2+1] = htole16( (int16_t) (Q * 32768.0) );
|
||||||
|
|
||||||
|
testdata_sc16q11[i*2] = htole16( (int16_t) (I * 2048.0) );
|
||||||
|
testdata_sc16q11[i*2+1] = htole16( (int16_t) (Q * 2048.0) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void test(const char *what, input_format_t format, void *data, double sample_rate, bool filter_dc) {
|
||||||
|
fprintf(stderr, "Benchmarking: %s ", what);
|
||||||
|
|
||||||
|
struct converter_state *state;
|
||||||
|
iq_convert_fn converter = init_converter(format, sample_rate, filter_dc, &state);
|
||||||
|
if (!converter) {
|
||||||
|
fprintf(stderr, "Can't initialize converter\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct timespec total = { 0, 0 };
|
||||||
|
int iterations = 0;
|
||||||
|
|
||||||
|
// Run it once to force init.
|
||||||
|
converter(data, outdata, MODES_MAG_BUF_SAMPLES, state, NULL, NULL);
|
||||||
|
|
||||||
|
while (total.tv_sec < 5) {
|
||||||
|
fprintf(stderr, ".");
|
||||||
|
|
||||||
|
struct timespec start;
|
||||||
|
start_cpu_timing(&start);
|
||||||
|
|
||||||
|
for (int i = 0; i < 10; ++i) {
|
||||||
|
converter(data, outdata, MODES_MAG_BUF_SAMPLES, state, NULL, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
end_cpu_timing(&start, &total);
|
||||||
|
iterations++;
|
||||||
|
}
|
||||||
|
|
||||||
|
fprintf(stderr, "\n");
|
||||||
|
cleanup_converter(state);
|
||||||
|
|
||||||
|
double samples = 10.0 * iterations * MODES_MAG_BUF_SAMPLES;
|
||||||
|
double nanos = total.tv_sec * 1e9 + total.tv_nsec;
|
||||||
|
fprintf(stderr, " %.2fM samples in %.6f seconds\n",
|
||||||
|
samples / 1e6, nanos / 1e9);
|
||||||
|
fprintf(stderr, " %.2fM samples/second\n",
|
||||||
|
samples / nanos * 1e3);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
MODES_NOTUSED(argc);
|
||||||
|
MODES_NOTUSED(argv);
|
||||||
|
|
||||||
|
prepare();
|
||||||
|
|
||||||
|
test("SC16Q11, DC", INPUT_SC16Q11, testdata_sc16q11, 2400000, true);
|
||||||
|
test("SC16Q11, no DC", INPUT_SC16Q11, testdata_sc16q11, 2400000, false);
|
||||||
|
|
||||||
|
test("UC8, DC", INPUT_UC8, testdata_uc8, 2400000, true);
|
||||||
|
test("UC8, no DC", INPUT_UC8, testdata_uc8, 2400000, false);
|
||||||
|
|
||||||
|
test("SC16, DC", INPUT_SC16, testdata_sc16, 2400000, true);
|
||||||
|
test("SC16, no DC", INPUT_SC16, testdata_sc16, 2400000, false);
|
||||||
|
}
|
Loading…
Reference in a new issue