audioconvert: add format conversion benchmark

This commit is contained in:
Wim Taymans 2019-01-24 09:49:19 +01:00
parent 6f586602af
commit dd66469570
2 changed files with 145 additions and 0 deletions

View file

@ -31,7 +31,149 @@
#include "fmt-ops.c" #include "fmt-ops.c"
#define N_SAMPLES 4096
#define N_CHANNELS 5
#define MAX_COUNT 1000
static uint8_t samp_in[N_SAMPLES * N_CHANNELS * 4];
static uint8_t samp_out[N_SAMPLES * N_CHANNELS * 4];
static void run_test(const char *name, bool in_packed, bool out_packed, convert_func_t func)
{
const void *ip[N_CHANNELS];
void *op[N_CHANNELS];
int i, j, ic, oc, ns;
struct timespec ts;
uint64_t t1, t2;
uint64_t count = 0;
for (j = 0; j < N_CHANNELS; j++) {
ip[j] = &samp_in[j * N_SAMPLES * 4];
op[j] = &samp_out[j * N_SAMPLES * 4];
}
ic = in_packed ? 1 : N_CHANNELS;
oc = out_packed ? 1 : N_CHANNELS;
ns = (in_packed && out_packed) ? N_SAMPLES * N_CHANNELS : N_SAMPLES;
clock_gettime(CLOCK_MONOTONIC, &ts);
t1 = SPA_TIMESPEC_TO_NSEC(&ts);
for (i = 0; i < MAX_COUNT; i++) {
func(NULL, oc, op, ic, ip, ns);
count++;
}
count *= N_SAMPLES;
clock_gettime(CLOCK_MONOTONIC, &ts);
t2 = SPA_TIMESPEC_TO_NSEC(&ts);
fprintf(stderr, "%s: elapsed %"PRIu64" count %"PRIu64" = %"PRIu64"/sec\n", name,
t2 - t1, count, count * (uint64_t)SPA_NSEC_PER_SEC / (t2 - t1));
}
static void test_f32_u8(void)
{
run_test("test_f32_u8", true, true, conv_f32_to_u8);
run_test("test_f32d_u8", false, true, conv_f32d_to_u8);
run_test("test_f32_u8d", true, false, conv_f32_to_u8d);
}
static void test_u8_f32(void)
{
run_test("test_u8_f32", true, true, conv_u8_to_f32);
run_test("test_u8d_f32", false, true, conv_u8d_to_f32);
run_test("test_u8_f32d", true, false, conv_u8_to_f32d);
}
static void test_f32_s16(void)
{
run_test("test_f32_s16", true, true, conv_f32_to_s16);
run_test("test_f32d_s16", false, true, conv_f32d_to_s16);
run_test("test_f32_s16d", true, false, conv_f32_to_s16d);
}
static void test_s16_f32(void)
{
run_test("test_s16_f32", true, true, conv_s16_to_f32);
run_test("test_s16d_f32", false, true, conv_s16d_to_f32);
run_test("test_s16_f32d", true, false, conv_s16_to_f32d);
}
static void test_f32_s32(void)
{
run_test("test_f32_s32", true, true, conv_f32_to_s32);
run_test("test_f32d_s32", false, true, conv_f32d_to_s32);
run_test("test_f32_s32d", true, false, conv_f32_to_s32d);
}
static void test_s32_f32(void)
{
run_test("test_s32_f32", true, true, conv_s32_to_f32);
run_test("test_s32d_f32", false, true, conv_s32d_to_f32);
run_test("test_s32_f32d", true, false, conv_s32_to_f32d);
}
static void test_f32_s24(void)
{
run_test("test_f32_s24", true, true, conv_f32_to_s24);
run_test("test_f32d_s24", false, true, conv_f32d_to_s24);
run_test("test_f32_s24d", true, false, conv_f32_to_s24d);
}
static void test_s24_f32(void)
{
run_test("test_s24_f32", true, true, conv_s24_to_f32);
run_test("test_s24d_f32", false, true, conv_s24d_to_f32);
run_test("test_s24_f32d", true, false, conv_s24_to_f32d);
}
static void test_f32_s24_32(void)
{
run_test("test_f32_s24_32", true, true, conv_f32_to_s24_32);
run_test("test_f32d_s24_32", false, true, conv_f32d_to_s24_32);
run_test("test_f32_s24_32d", true, false, conv_f32_to_s24_32d);
}
static void test_s24_32_f32(void)
{
run_test("test_s24_32_f32", true, true, conv_s24_32_to_f32);
run_test("test_s24_32d_f32", false, true, conv_s24_32d_to_f32);
run_test("test_s24_32_f32d", true, false, conv_s24_32_to_f32d);
}
static void test_interleave(void)
{
run_test("test_interleave_8", false, true, interleave_8);
run_test("test_interleave_16", false, true, interleave_16);
run_test("test_interleave_24", false, true, interleave_24);
run_test("test_interleave_32", false, true, interleave_32);
}
static void test_deinterleave(void)
{
run_test("test_deinterleave_8", true, false, deinterleave_8);
run_test("test_deinterleave_16", true, false, deinterleave_16);
run_test("test_deinterleave_24", true, false, deinterleave_24);
run_test("test_deinterleave_32", true, false, deinterleave_32);
}
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
find_conv_info(0, 0, 0);
test_f32_u8();
test_u8_f32();
test_f32_s16();
test_s16_f32();
test_f32_s32();
test_s32_f32();
test_f32_s24();
test_s24_f32();
test_f32_s24_32();
test_s24_32_f32();
test_interleave();
test_deinterleave();
return 0; return 0;
} }

View file

@ -238,6 +238,9 @@ static void test_s24_32_f32(void)
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
find_conv_info(0, 0, 0);
test_f32_u8(); test_f32_u8();
test_u8_f32(); test_u8_f32();
test_f32_s16(); test_f32_s16();