diff options
author | Jakob Odersky <jodersky@gmail.com> | 2012-06-18 18:43:59 +0200 |
---|---|---|
committer | Jakob Odersky <jodersky@gmail.com> | 2012-06-18 18:52:04 +0200 |
commit | 7272062cee1f62854544d95458359a1b957cdf05 (patch) | |
tree | f0419177cffd7fa007ffac2380b2562029fe0a29 /src/benchmark.c | |
parent | b1fa4f7b3dd158db9b17ff3cf0238075170dc5b1 (diff) | |
download | k8055-7272062cee1f62854544d95458359a1b957cdf05.tar.gz k8055-7272062cee1f62854544d95458359a1b957cdf05.tar.bz2 k8055-7272062cee1f62854544d95458359a1b957cdf05.zip |
*add tests
*add debug setting
*modify header comments
Diffstat (limited to 'src/benchmark.c')
-rw-r--r-- | src/benchmark.c | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/benchmark.c b/src/benchmark.c new file mode 100644 index 0000000..185e738 --- /dev/null +++ b/src/benchmark.c @@ -0,0 +1,40 @@ +#include <stdio.h> +#include <stdlib.h> +#include <sys/time.h> +#include "k8055.h" + + +#define ITERATIONS 1000 + +int main(int argc, char *argv[]) { + int port; + if (argc <= 1) port = 0; + else port = atoi(argv[1]); + + k8055_device* device; + if (k8055_open_device(port, &device) != 0) { + printf("could not open board on port %i\n", port); + return -1; + }; + + struct timeval t0; + struct timeval t; + + int us = 0; + for (int i = 0; i < ITERATIONS; ++i) { + gettimeofday(&t0, NULL); + k8055_get_all_input(device, NULL, NULL, NULL, NULL, NULL, false); + gettimeofday(&t, NULL); + us += (t.tv_sec - t0.tv_sec) * 1000000 + t.tv_usec - t0.tv_usec; + } + printf("average read time for %i iterations: %i [ms]\n", ITERATIONS, us / ITERATIONS / 1000); + + us = 0; + for (int i = 0; i < ITERATIONS; ++i) { + gettimeofday(&t0, NULL); + k8055_get_all_input(device, NULL, NULL, NULL, NULL, NULL, true); + gettimeofday(&t, NULL); + us += (t.tv_sec - t0.tv_sec) * 1000000 + t.tv_usec - t0.tv_usec; + } + printf("average quick read time for %i iterations: %i [ms]\n", ITERATIONS, us / ITERATIONS / 1000); +} |