summaryrefslogtreecommitdiffstats
path: root/include/util/timer.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/util/timer.h')
-rw-r--r--include/util/timer.h37
1 files changed, 37 insertions, 0 deletions
diff --git a/include/util/timer.h b/include/util/timer.h
new file mode 100644
index 0000000..a9784a8
--- /dev/null
+++ b/include/util/timer.h
@@ -0,0 +1,37 @@
+/*
+ * include/util/timer.h
+ *
+ * Copyright (C) 2023 Douglas Rumbaugh <drumbaugh@psu.edu>
+ *
+ * All rights reserved. Published under the Modified BSD License.
+ *
+ */
+#pragma once
+
+#include <chrono>
+
+#ifdef ENABLE_TIMER
+#define TIMER_INIT() \
+ auto timer_start = std::chrono::high_resolution_clock::now(); \
+ auto timer_stop = std::chrono::high_resolution_clock::now();
+
+#define TIMER_START() \
+ timer_start = std::chrono::high_resolution_clock::now()
+
+#define TIMER_STOP() \
+ timer_stop = std::chrono::high_resolution_clock::now()
+
+#define TIMER_RESULT() \
+ std::chrono::duration_cast<std::chrono::nanoseconds>(timer_stop - timer_start).count()
+
+#else
+ #define TIMER_INIT() \
+ do {} while(0)
+ #define TIMER_START() \
+ do {} while(0)
+ #define TIMER_STOP() \
+ do {} while(0)
+ #define TIMER_RESULT() \
+ 0l
+#endif
+