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.
This commit is contained in:
flatmush 2011-02-24 17:13:30 +00:00
parent a9ff155dcc
commit 3fc97475e1
2 changed files with 38 additions and 32 deletions

View File

@ -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
<stdio.h>
<stdlib.h>
<math.h>

View File

@ -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_duration = 0;
hiclock_t flt_duration = 0;
fix16_t fix_error = 0;
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();
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);
}
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: %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;
}