summaryrefslogtreecommitdiffstats
path: root/test/timer.c
diff options
context:
space:
mode:
Diffstat (limited to 'test/timer.c')
-rw-r--r--test/timer.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/test/timer.c b/test/timer.c
new file mode 100644
index 0000000..43aff84
--- /dev/null
+++ b/test/timer.c
@@ -0,0 +1,33 @@
+#include <stdlib.h>
+#include "timer.h"
+
+
+Timer *
+timer_new (void)
+{
+ Timer *t = (Timer *) malloc (sizeof (Timer));
+ t->seconds = t->useconds = 0L;
+ return t;
+}
+
+void
+timer_destroy (Timer *t)
+{
+ free (t);
+}
+
+void
+timer_start (Timer *t)
+{
+ gettimeofday(&t->start, NULL);
+}
+
+void
+timer_stop (Timer *t)
+{
+ struct timeval end;
+
+ gettimeofday(&end, NULL);
+ t->seconds += end.tv_sec - t->start.tv_sec;
+ t->useconds += end.tv_usec - t->start.tv_usec;
+}