summaryrefslogtreecommitdiff
path: root/meme/time.c
diff options
context:
space:
mode:
authorWerner Almesberger <werner@almesberger.net>2014-09-12 13:29:01 (GMT)
committerWerner Almesberger <werner@almesberger.net>2014-09-12 13:29:01 (GMT)
commit60c8902fe151eb4b87796badf68eb3bea60cf58e (patch)
tree75cb69a7fb6dd5ff05e044f46912e115ac53b304 /meme/time.c
parent173e5325d1968ff88a0788c8d1248841dd381f15 (diff)
downloadmisc-60c8902fe151eb4b87796badf68eb3bea60cf58e.zip
misc-60c8902fe151eb4b87796badf68eb3bea60cf58e.tar.gz
misc-60c8902fe151eb4b87796badf68eb3bea60cf58e.tar.bz2
meme/time.h, meme/time.c: utilities to measure program execution time
Diffstat (limited to 'meme/time.c')
-rw-r--r--meme/time.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/meme/time.c b/meme/time.c
new file mode 100644
index 0000000..1d366d1
--- /dev/null
+++ b/meme/time.c
@@ -0,0 +1,39 @@
+/*
+ * time.h - Timing of program execution
+ *
+ * Written 2014 by Werner Almesberger
+ * Copyright 2014 by Werner Almesberger
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+
+#include <stddef.h>
+#include <sys/time.h>
+
+#include "time.h"
+
+
+void time_start(struct time *t)
+{
+ gettimeofday(&t->tv, NULL);
+}
+
+
+void time_stop(struct time *t)
+{
+ struct timeval now;
+
+ gettimeofday(&now, NULL);
+ t->tv.tv_sec -= now.tv_sec;
+ t->tv.tv_usec -= now.tv_usec;
+}
+
+
+unsigned time_ms(const struct time *t)
+{
+ return -t->tv.tv_sec*1000 - t->tv.tv_usec/1000;
+}