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 /fixtest/main.c | |
| 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.
Diffstat (limited to 'fixtest/main.c')
| -rw-r--r-- | fixtest/main.c | 60 |
1 files changed, 60 insertions, 0 deletions
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;
+}
|
