summaryrefslogtreecommitdiff
path: root/meme
diff options
context:
space:
mode:
authorWerner Almesberger <werner@almesberger.net>2014-09-12 10:29:01 -0300
committerWerner Almesberger <werner@almesberger.net>2014-09-12 10:29:01 -0300
commit60c8902fe151eb4b87796badf68eb3bea60cf58e (patch)
tree75cb69a7fb6dd5ff05e044f46912e115ac53b304 /meme
parent173e5325d1968ff88a0788c8d1248841dd381f15 (diff)
downloadmisc-60c8902fe151eb4b87796badf68eb3bea60cf58e.tar.gz
misc-60c8902fe151eb4b87796badf68eb3bea60cf58e.tar.bz2
misc-60c8902fe151eb4b87796badf68eb3bea60cf58e.zip
meme/time.h, meme/time.c: utilities to measure program execution time
Diffstat (limited to 'meme')
-rw-r--r--meme/Makefile2
-rw-r--r--meme/time.c39
-rw-r--r--meme/time.h29
3 files changed, 69 insertions, 1 deletions
diff --git a/meme/Makefile b/meme/Makefile
index be00b3b..7857262 100644
--- a/meme/Makefile
+++ b/meme/Makefile
@@ -13,7 +13,7 @@
include Makefile.c-common
CFLAGS = -Wall -Wshadow -g -O9
-OBJS = main.o stl.o mesh.o gui.o
+OBJS = main.o stl.o mesh.o gui.o time.o
CFLAGS += $(shell sdl-config --cflags)
LDLIBS = $(shell sdl-config --libs) -lSDL_gfx -lm
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;
+}
diff --git a/meme/time.h b/meme/time.h
new file mode 100644
index 0000000..e4c244e
--- /dev/null
+++ b/meme/time.h
@@ -0,0 +1,29 @@
+/*
+ * 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.
+ */
+
+
+#ifndef TIME_H
+#define TIME_H
+
+#include <sys/time.h>
+
+
+struct time {
+ struct timeval tv;
+};
+
+
+void time_start(struct time *t);
+void time_stop(struct time *t);
+unsigned time_ms(const struct time *t);
+
+#endif /* !TIME_H */