aboutsummaryrefslogtreecommitdiff
path: root/src/benchmark.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/benchmark.c')
-rw-r--r--src/benchmark.c40
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);
+}