Mercurial > vec
view test/test_benchmark.h @ 37:4b5a557aa64f
*: turns out extern is a practical joke. rewrite to be always inline again
the sample benchmark performs about 3x as well with optimizations
disabled :)
author | Paper <paper@tflc.us> |
---|---|
date | Sat, 26 Apr 2025 01:04:35 -0400 |
parents | |
children | f9ca85d2f14c |
line wrap: on
line source
/* ------------------------------------------------------------------------ */ /* simple benchmark for getting the min/max range of an audio sample. */ /* prevent GCC from optimizing these function calls away - i think there's * probably a better way to do this, but I haven't found it yet :) */ extern void test_benchmark_sample_minmax_simple_impl(int16_t *smpl, uint32_t length, int32_t *pmin, int32_t *pmax); extern void test_benchmark_sample_minmax_vec_impl(int16_t *smpl, uint32_t length, int32_t *pmin, int32_t *pmax); VEC_FUNC_IMPL void test_benchmark_sample_minmax(void) { int32_t min, max; clock_t start, end; int i; int16_t *q = vec_malloc(16000000u * 2u); printf("\nsigned 16-bit audio sample min/max - 1 thousand passes - 16000000 samples\n\n"); /* generate random sample values */ for (i = 0; i < 16000000; i++) q[i] = rand(); start = clock(); for (i = 0; i < 1000; i++) { min = INT32_MAX; max = INT32_MIN; test_benchmark_sample_minmax_vec_impl(q, 16000000u, &min, &max); } end = clock(); printf("- vec: took %f secs\n", (double)(end - start) / CLOCKS_PER_SEC); start = clock(); for (i = 0; i < 1000; i++) { min = INT32_MAX; max = INT32_MIN; test_benchmark_sample_minmax_simple_impl(q, 16000000u, &min, &max); } end = clock(); printf("- simple: took %f secs\n", (double)(end - start) / CLOCKS_PER_SEC); printf("\n"); vec_free(q); } static void test_benchmark(void) { printf("------- BENCHMARK --------\n"); test_benchmark_sample_minmax(); }