From 3fc97475e182d03053bfcac327b916db5a9ee2a1 Mon Sep 17 00:00:00 2001 From: flatmush Date: Thu, 24 Feb 2011 17:13:30 +0000 Subject: Added multi-pass approach to fixtest, now produces more accurate results. On x86 with an FPU and full optimization fixed point is about 20% slower than floating point. The multi-pass approach means that this test should run unmodified on embedded environments due to lower memory usage, this test also more realistically tests for cache behaviour. --- fixtest/fixtest.depend | 2 +- fixtest/main.c | 66 +++++++++++++++++++++++++++----------------------- 2 files changed, 37 insertions(+), 31 deletions(-) diff --git a/fixtest/fixtest.depend b/fixtest/fixtest.depend index ac2f94a..db7e8ce 100644 --- a/fixtest/fixtest.depend +++ b/fixtest/fixtest.depend @@ -1,5 +1,5 @@ # depslib dependency file v1.0 -1298566464 source:g:\vrfx\libfixmath\fixtest\main.c +1298567472 source:g:\vrfx\libfixmath\fixtest\main.c diff --git a/fixtest/main.c b/fixtest/main.c index 86a2c23..a7e9e89 100644 --- a/fixtest/main.c +++ b/fixtest/main.c @@ -14,47 +14,53 @@ int main(int argc, char** argv) { hiclock_init(); - uintptr_t iter = (1 << 16); + uintptr_t args = (1 << 8); + uintptr_t iter = (1 << 8); uintptr_t pass = (1 << 8); uintptr_t i; srand(time(NULL)); - fix16_t fix_args[iter]; - for(i = 0; i < iter; i++) - fix_args[i] = (rand() ^ (rand() << 16)); - fix16_t fix_result[iter]; - hiclock_t fix_start = hiclock(); - for(i = 0; i < pass; i++) { - uintptr_t j; - for(j = 0; j < iter; j++) - fix_result[j] = fix16_atan(fix_args[j]); - } - hiclock_t fix_end = hiclock(); - - float flt_args[iter]; - for(i = 0; i < iter; i++) - flt_args[i] = fix16_to_float(fix_args[i]); - float flt_result[iter]; - hiclock_t flt_start = hiclock(); - for(i = 0; i < pass; i++) { - uintptr_t j; - for(j = 0; j < iter; j++) - flt_result[j] = atanf(flt_args[j]); - } - hiclock_t flt_end = hiclock(); + hiclock_t fix_duration = 0; + hiclock_t flt_duration = 0; + fix16_t fix_error = 0; - fix16_t fix_error = 0; - for(i = 0; i < iter; i++) - fix_error += abs(fix16_from_float(flt_result[i]) - fix_result[i]); + uintptr_t k; + for(k = 0; k < pass; k++) { + fix16_t fix_args[args]; + for(i = 0; i < args; i++) + fix_args[i] = (rand() ^ (rand() << 16)); + fix16_t fix_result[args]; + hiclock_t fix_start = hiclock(); + for(i = 0; i < iter; i++) { + uintptr_t j; + for(j = 0; j < args; j++) + fix_result[j] = fix16_atan(fix_args[j]); + } + hiclock_t fix_end = hiclock(); - hiclock_t flt_duration = (flt_end - flt_start); - hiclock_t fix_duration = (fix_end - fix_start); + float flt_args[args]; + for(i = 0; i < args; i++) + flt_args[i] = fix16_to_float(fix_args[i]); + float flt_result[args]; + hiclock_t flt_start = hiclock(); + for(i = 0; i < iter; i++) { + uintptr_t j; + for(j = 0; j < args; j++) + flt_result[j] = atanf(flt_args[j]); + } + hiclock_t flt_end = hiclock(); + + for(i = 0; i < args; i++) + fix_error += abs(fix16_from_float(flt_result[i]) - fix_result[i]); + flt_duration += (flt_end - flt_start); + fix_duration += (fix_end - fix_start); + } printf("Floating Point: %08"PRIuHICLOCK" @ %"PRIu32"Hz\n", flt_duration, HICLOCKS_PER_SEC); printf("Fixed Point: %08"PRIuHICLOCK" @ %"PRIu32"Hz\n", fix_duration, HICLOCKS_PER_SEC); printf("Difference: %08"PRIiHICLOCK" (% 3.2f%%)\n", (flt_duration - fix_duration), ((fix_duration * 100.0) / flt_duration)); - printf("Error: %f%%\n", ((fix16_to_dbl(fix_error) * 100.0) / iter)); + printf("Error: %f%%\n", ((fix16_to_dbl(fix_error) * 100.0) / (args * pass))); return EXIT_SUCCESS; } -- cgit v1.2.3