From d3482256c277dff8cd6243dae0f72df1a4c676d3 Mon Sep 17 00:00:00 2001 From: flatmush Date: Thu, 24 Feb 2011 16:23:50 +0000 Subject: Added a small program called fixtest which currently tests performance and average error on x86 platforms, currently it produces quite wildly varying results depending on the input values. The average error seems to vary between 3-8%, it's possible that setting iter to a higher value (and pass to a lower one) could give a more stable value. Fixed point seems to be slower overall on x86 (50% of float) with good floating point hardware, however with the caching enabled depending on the program the fixed point implementation may be much faster (as float would be if cached). With caching enabled there is a massive difference between and iter size below and above 4096, this is because the caching mechanism thrashes above this threshold, it probably makes sense to disable caching for these tests by compiling libfixmath with FIXMATH_NO_CACHE. --- fixtest/fixtest.cbp | 52 +++++++++++++++++++++++++++++++++++++++++++ fixtest/fixtest.depend | 34 ++++++++++++++++++++++++++++ fixtest/fixtest.layout | 13 +++++++++++ fixtest/hiclock.c | 25 +++++++++++++++++++++ fixtest/hiclock.h | 33 +++++++++++++++++++++++++++ fixtest/main.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 217 insertions(+) create mode 100644 fixtest/fixtest.cbp create mode 100644 fixtest/fixtest.depend create mode 100644 fixtest/fixtest.layout create mode 100644 fixtest/hiclock.c create mode 100644 fixtest/hiclock.h create mode 100644 fixtest/main.c diff --git a/fixtest/fixtest.cbp b/fixtest/fixtest.cbp new file mode 100644 index 0000000..2671252 --- /dev/null +++ b/fixtest/fixtest.cbp @@ -0,0 +1,52 @@ + + + + + + diff --git a/fixtest/fixtest.depend b/fixtest/fixtest.depend new file mode 100644 index 0000000..92b569d --- /dev/null +++ b/fixtest/fixtest.depend @@ -0,0 +1,34 @@ +# depslib dependency file v1.0 +1298564214 source:g:\vrfx\libfixmath\fixtest\main.c + + + + + + + "hiclock.h" + +1298453688 g:\vrfx\libfixmath\\libfixmath\fixmath.h + "uint32.h" + "fract32.h" + "fix16.h" + +1298453688 g:\vrfx\libfixmath\\libfixmath\uint32.h + + +1298453688 g:\vrfx\libfixmath\\libfixmath\fract32.h + + +1298454206 g:\vrfx\libfixmath\\libfixmath\fix16.h + + +1298562746 source:g:\vrfx\libfixmath\fixtest\hiclock.c + "hiclock.h" + +1298564182 g:\vrfx\libfixmath\fixtest\hiclock.h + + + + + + diff --git a/fixtest/fixtest.layout b/fixtest/fixtest.layout new file mode 100644 index 0000000..6606349 --- /dev/null +++ b/fixtest/fixtest.layout @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/fixtest/hiclock.c b/fixtest/hiclock.c new file mode 100644 index 0000000..94ed735 --- /dev/null +++ b/fixtest/hiclock.c @@ -0,0 +1,25 @@ +#include "hiclock.h" + +#if defined(__WIN32) || defined(__WIN64) +LONGLONG HICLOCKS_PER_SEC = 0; + +void hiclock_init() { + LARGE_INTEGER freq; + QueryPerformanceFrequency(&freq); + HICLOCKS_PER_SEC = freq.QuadPart; +} +#endif + +hiclock_t hiclock() { + #if defined(__unix__) + timeval clocks; + gettimeofday(&clocks, NULL); + return ((uint64_t)clocks.tv_sec * 1000000ULL) + clocks.tv_usec; + #elif defined(__WIN32) || defined(__WIN64) + LARGE_INTEGER clocks; + QueryPerformanceCounter(&clocks); + return clocks.QuadPart; + #else + return clock(); + #endif +} diff --git a/fixtest/hiclock.h b/fixtest/hiclock.h new file mode 100644 index 0000000..89e32c8 --- /dev/null +++ b/fixtest/hiclock.h @@ -0,0 +1,33 @@ +#ifndef __hiclock_h__ +#define __hiclock_h__ + +#include +#include + +#if defined(__unix__) +#include +#define PRIuHICLOCK PRIu64 +#define PRIiHICLOCK PRIi64 +typedef uint64_t hiclock_t; +#define HICLOCKS_PER_SEC 1000000 +#define hiclock_init() +#elif defined(__WIN32) || defined(__WIN64) +#include +#define PRIuHICLOCK PRIu64 +#define PRIiHICLOCK PRIi64 +typedef LONGLONG hiclock_t; +extern LONGLONG HICLOCKS_PER_SEC; +extern void hiclock_init(); +#else +#include +#define PRIuHICLOCK PRIu32 +#define PRIiHICLOCK PRIi32 +typedef clock_t hiclock_t; +#define HICLOCKS_PER_SEC CLOCKS_PER_SEC +#define hiclock_init() +#endif + +extern hiclock_t hiclock(); + +#endif + diff --git a/fixtest/main.c b/fixtest/main.c new file mode 100644 index 0000000..4c99381 --- /dev/null +++ b/fixtest/main.c @@ -0,0 +1,60 @@ +#include +#include +#include +#include +#include + +#include + +#include "hiclock.h" + + +int main(int argc, char** argv) { + printf("libfixmath test tool\n"); + + hiclock_init(); + + uintptr_t iter = (1 << 16); + 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(); + + fix16_t fix_error = 0; + for(i = 0; i < iter; i++) + fix_error += abs(fix16_from_float(flt_result[i]) - fix_result[i]); + + hiclock_t flt_duration = (flt_end - flt_start); + hiclock_t 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: % 3.2f%%\n", ((double)fix_error / iter)); + + return EXIT_SUCCESS; +} -- cgit v1.2.3