diff options
| author | Petteri Aimonen <jpa@github.mail.kapsi.fi> | 2021-04-22 11:04:01 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-04-22 11:04:01 +0300 |
| commit | b20bdb01d9da65bcffac57e116044060836142d1 (patch) | |
| tree | a8680595fd82f9ad406d1f2d5a90c8e623ced1a4 /fixtest | |
| parent | 24488b16cc0359daada0682a9bd3a11a801d0a01 (diff) | |
| parent | 17a6197819236bc9ca9eb8826bfd3b18e63ddabd (diff) | |
| download | libfixmath-b20bdb01d9da65bcffac57e116044060836142d1.tar.gz | |
Merge pull request #25 from maruncz/master
Added CMakeLists.txt and some fixes
Diffstat (limited to 'fixtest')
| -rw-r--r-- | fixtest/hiclock.c | 17 | ||||
| -rw-r--r-- | fixtest/main.c | 109 |
2 files changed, 69 insertions, 57 deletions
diff --git a/fixtest/hiclock.c b/fixtest/hiclock.c index 94ed735..5ce58df 100644 --- a/fixtest/hiclock.c +++ b/fixtest/hiclock.c @@ -1,25 +1,28 @@ #include "hiclock.h"
+#include <stddef.h>
#if defined(__WIN32) || defined(__WIN64)
LONGLONG HICLOCKS_PER_SEC = 0;
-void hiclock_init() {
+void hiclock_init()
+{
LARGE_INTEGER freq;
QueryPerformanceFrequency(&freq);
HICLOCKS_PER_SEC = freq.QuadPart;
}
#endif
-hiclock_t hiclock() {
- #if defined(__unix__)
- timeval clocks;
+hiclock_t hiclock()
+{
+#if defined(__unix__)
+ struct timeval clocks;
gettimeofday(&clocks, NULL);
return ((uint64_t)clocks.tv_sec * 1000000ULL) + clocks.tv_usec;
- #elif defined(__WIN32) || defined(__WIN64)
+#elif defined(__WIN32) || defined(__WIN64)
LARGE_INTEGER clocks;
QueryPerformanceCounter(&clocks);
return clocks.QuadPart;
- #else
+#else
return clock();
- #endif
+#endif
}
diff --git a/fixtest/main.c b/fixtest/main.c index e4f105a..5f6dd92 100644 --- a/fixtest/main.c +++ b/fixtest/main.c @@ -1,87 +1,96 @@ +#include "hiclock.h"
+#include <inttypes.h>
+#include <libfixmath/fixmath.h>
+#include <math.h>
#include <stdio.h>
#include <stdlib.h>
-#include <math.h>
#include <time.h>
-#include <inttypes.h>
-
-#include <libfixmath/fixmath.h>
-
-#include "hiclock.h"
-
-//#define fix_func fix16_exp
-//#define fix_func_str "fix16_exp"
-//#define flt_func expf
-//#define flt_func_str "expf"
-//#define fix_func fix16_atan
-//#define fix_func_str "fix16_atan"
-//#define flt_func atanf
-//#define flt_func_str "atanf"
-
-#define fix_func fix16_sin
+#define EXP
+//#define ATAN
+//#define SIN
+//#define SQRT
+
+#ifdef EXP
+#define fix_func fix16_exp
+#define fix_func_str "fix16_exp"
+#define flt_func expf
+#define flt_func_str "expf"
+#endif
+
+#ifdef ATAN
+#define fix_func fix16_atan
+#define fix_func_str "fix16_atan"
+#define flt_func atanf
+#define flt_func_str "atanf"
+#endif
+
+#ifdef SIN
+#define fix_func fix16_sin
#define fix_func_str "fix16_sin"
-#define flt_func sinf
+#define flt_func sinf
#define flt_func_str "sinf"
+#endif
-//#define fix_func fix16_sqrt
-//#define fix_func_str "fix16_sqrt"
-//#define flt_func sqrtf
-//#define flt_func_str "sqrtf"
-
-
+#ifdef SQRT
+#define fix_func fix16_sqrt
+#define fix_func_str "fix16_sqrt"
+#define flt_func sqrtf
+#define flt_func_str "sqrtf"
+#endif
-int main(int argc, char** argv) {
- printf("libfixmath test tool\n");
+int main(int argc, char **argv)
+{
+ printf("libfixmath test tool\n");
- hiclock_init();
+ hiclock_init();
- uintptr_t args = (1 << 8);
- uintptr_t iter = (1 << 8);
- uintptr_t pass = (1 << 8);
+ uintptr_t args = (1 << 8);
+ uintptr_t iter = (1 << 8);
+ uintptr_t pass = (1 << 8);
uintptr_t i;
srand(time(NULL));
hiclock_t fix_duration = 0;
hiclock_t flt_duration = 0;
- fix16_t fix_error = 0;
+ fix16_t fix_error = 0;
uintptr_t k;
- for(k = 0; k < pass; 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];
+ 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++) {
+ for (i = 0; i < iter; i++)
+ {
uintptr_t j;
- for(j = 0; j < args; j++)
- fix_result[j] = fix_func(fix_args[j]);
+ for (j = 0; j < args; j++) fix_result[j] = fix_func(fix_args[j]);
}
hiclock_t fix_end = hiclock();
- float flt_args[args];
- for(i = 0; i < args; i++)
- flt_args[i] = fix16_to_float(fix_args[i]);
- float flt_result[args];
+ 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++) {
+ for (i = 0; i < iter; i++)
+ {
uintptr_t j;
- for(j = 0; j < args; j++)
- flt_result[j] = flt_func(flt_args[j]);
+ for (j = 0; j < args; j++) flt_result[j] = flt_func(flt_args[j]);
}
hiclock_t flt_end = hiclock();
- for(i = 0; i < args; i++)
+ 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("%16s: %08"PRIuHICLOCK" @ %"PRIu32"Hz\n", flt_func_str, flt_duration, HICLOCKS_PER_SEC);
- printf("%16s: %08"PRIuHICLOCK" @ %"PRIu32"Hz\n", fix_func_str, fix_duration, HICLOCKS_PER_SEC);
- printf(" Difference: %08"PRIiHICLOCK" (% 3.2f%%)\n", (flt_duration - fix_duration), ((fix_duration * 100.0) / flt_duration));
+ printf("%16s: %08" PRIuHICLOCK " @ %" PRIu32 "Hz\n", flt_func_str, flt_duration, HICLOCKS_PER_SEC);
+ printf("%16s: %08" PRIuHICLOCK " @ %" PRIu32 "Hz\n", fix_func_str, 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) / (args * pass)));
- return EXIT_SUCCESS;
+ return EXIT_SUCCESS;
}
|
