Mercurial > vec
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 36:677c03c382b8 | 37:4b5a557aa64f |
|---|---|
| 1 | |
| 2 /* ------------------------------------------------------------------------ */ | |
| 3 /* simple benchmark for getting the min/max range of an audio sample. */ | |
| 4 | |
| 5 /* prevent GCC from optimizing these function calls away - i think there's | |
| 6 * probably a better way to do this, but I haven't found it yet :) */ | |
| 7 | |
| 8 | |
| 9 extern void test_benchmark_sample_minmax_simple_impl(int16_t *smpl, uint32_t length, int32_t *pmin, int32_t *pmax); | |
| 10 extern void test_benchmark_sample_minmax_vec_impl(int16_t *smpl, uint32_t length, int32_t *pmin, int32_t *pmax); | |
| 11 | |
| 12 VEC_FUNC_IMPL void test_benchmark_sample_minmax(void) | |
| 13 { | |
| 14 int32_t min, max; | |
| 15 clock_t start, end; | |
| 16 int i; | |
| 17 int16_t *q = vec_malloc(16000000u * 2u); | |
| 18 | |
| 19 printf("\nsigned 16-bit audio sample min/max - 1 thousand passes - 16000000 samples\n\n"); | |
| 20 | |
| 21 /* generate random sample values */ | |
| 22 for (i = 0; i < 16000000; i++) | |
| 23 q[i] = rand(); | |
| 24 | |
| 25 start = clock(); | |
| 26 for (i = 0; i < 1000; i++) { | |
| 27 min = INT32_MAX; | |
| 28 max = INT32_MIN; | |
| 29 test_benchmark_sample_minmax_vec_impl(q, 16000000u, &min, &max); | |
| 30 } | |
| 31 end = clock(); | |
| 32 | |
| 33 printf("- vec: took %f secs\n", (double)(end - start) / CLOCKS_PER_SEC); | |
| 34 | |
| 35 start = clock(); | |
| 36 for (i = 0; i < 1000; i++) { | |
| 37 min = INT32_MAX; | |
| 38 max = INT32_MIN; | |
| 39 test_benchmark_sample_minmax_simple_impl(q, 16000000u, &min, &max); | |
| 40 } | |
| 41 end = clock(); | |
| 42 | |
| 43 printf("- simple: took %f secs\n", (double)(end - start) / CLOCKS_PER_SEC); | |
| 44 | |
| 45 printf("\n"); | |
| 46 | |
| 47 vec_free(q); | |
| 48 } | |
| 49 | |
| 50 static void test_benchmark(void) | |
| 51 { | |
| 52 printf("------- BENCHMARK --------\n"); | |
| 53 test_benchmark_sample_minmax(); | |
| 54 } |
