diff options
| author | flatmush <flatmush@d3e1167c-abe1-51d5-8199-f9061ebe54e4> | 2011-02-24 16:23:50 +0000 |
|---|---|---|
| committer | flatmush <flatmush@d3e1167c-abe1-51d5-8199-f9061ebe54e4> | 2011-02-24 16:23:50 +0000 |
| commit | d3482256c277dff8cd6243dae0f72df1a4c676d3 (patch) | |
| tree | fb34a3f7ac03243e55f7cc3053e48c596a490e17 | |
| parent | 0e06a1e8b7fe9bb31437d8612d62bee85df2e43f (diff) | |
| download | libfixmath-d3482256c277dff8cd6243dae0f72df1a4c676d3.tar.gz | |
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.
| -rw-r--r-- | fixtest/fixtest.cbp | 52 | ||||
| -rw-r--r-- | fixtest/fixtest.depend | 34 | ||||
| -rw-r--r-- | fixtest/fixtest.layout | 13 | ||||
| -rw-r--r-- | fixtest/hiclock.c | 25 | ||||
| -rw-r--r-- | fixtest/hiclock.h | 33 | ||||
| -rw-r--r-- | fixtest/main.c | 60 |
6 files changed, 217 insertions, 0 deletions
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 @@ +<?xml version="1.0" encoding="UTF-8" standalone="yes" ?> +<CodeBlocks_project_file> + <FileVersion major="1" minor="6" /> + <Project> + <Option title="fixtest" /> + <Option pch_mode="2" /> + <Option compiler="gcc" /> + <Build> + <Target title="dbg"> + <Option output="bin\dbg\fixtest" prefix_auto="1" extension_auto="1" /> + <Option object_output="obj\dbg\" /> + <Option type="1" /> + <Option compiler="gcc" /> + <Compiler> + <Add option="-g" /> + </Compiler> + </Target> + <Target title="rel"> + <Option output="bin\rel\fixtest" prefix_auto="1" extension_auto="1" /> + <Option object_output="obj\rel\" /> + <Option type="1" /> + <Option compiler="gcc" /> + <Compiler> + <Add option="-O2" /> + </Compiler> + <Linker> + <Add option="-s" /> + </Linker> + </Target> + </Build> + <Compiler> + <Add option="-Wall" /> + <Add directory="..\" /> + </Compiler> + <Linker> + <Add library="..\libfixmath\libfixmath.a" /> + </Linker> + <Unit filename="hiclock.c"> + <Option compilerVar="CC" /> + </Unit> + <Unit filename="hiclock.h" /> + <Unit filename="main.c"> + <Option compilerVar="CC" /> + </Unit> + <Extensions> + <code_completion /> + <envvars /> + <debugger /> + <lib_finder disable_auto="1" /> + </Extensions> + </Project> +</CodeBlocks_project_file> 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
+ <stdio.h>
+ <stdlib.h>
+ <math.h>
+ <time.h>
+ <inttypes.h>
+ <libfixmath/fixmath.h>
+ "hiclock.h"
+
+1298453688 g:\vrfx\libfixmath\\libfixmath\fixmath.h
+ "uint32.h"
+ "fract32.h"
+ "fix16.h"
+
+1298453688 g:\vrfx\libfixmath\\libfixmath\uint32.h
+ <stdint.h>
+
+1298453688 g:\vrfx\libfixmath\\libfixmath\fract32.h
+ <stdint.h>
+
+1298454206 g:\vrfx\libfixmath\\libfixmath\fix16.h
+ <stdint.h>
+
+1298562746 source:g:\vrfx\libfixmath\fixtest\hiclock.c
+ "hiclock.h"
+
+1298564182 g:\vrfx\libfixmath\fixtest\hiclock.h
+ <stdint.h>
+ <inttypes.h>
+ <sys/time.h>
+ <windows.h>
+ <time.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 @@ +<?xml version="1.0" encoding="UTF-8" standalone="yes" ?> +<CodeBlocks_layout_file> + <ActiveTarget name="dbg" /> + <File name="hiclock.c" open="1" top="0" tabpos="3"> + <Cursor position="520" topLine="0" /> + </File> + <File name="hiclock.h" open="1" top="0" tabpos="2"> + <Cursor position="578" topLine="0" /> + </File> + <File name="main.c" open="1" top="1" tabpos="1"> + <Cursor position="139" topLine="30" /> + </File> +</CodeBlocks_layout_file> 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 <stdint.h>
+#include <inttypes.h>
+
+#if defined(__unix__)
+#include <sys/time.h>
+#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 <windows.h>
+#define PRIuHICLOCK PRIu64
+#define PRIiHICLOCK PRIi64
+typedef LONGLONG hiclock_t;
+extern LONGLONG HICLOCKS_PER_SEC;
+extern void hiclock_init();
+#else
+#include <time.h>
+#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 <stdio.h>
+#include <stdlib.h>
+#include <math.h>
+#include <time.h>
+#include <inttypes.h>
+
+#include <libfixmath/fixmath.h>
+
+#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;
+}
|
