summaryrefslogtreecommitdiffhomepage
path: root/FTNoIR_Tracker_PT/timer.cpp
diff options
context:
space:
mode:
authorPatrick Ruoff <c14-radioactive@19e81ba0-9b1a-49c3-bd6c-561e1906d5fb>2012-12-31 12:33:18 +0000
committerPatrick Ruoff <c14-radioactive@19e81ba0-9b1a-49c3-bd6c-561e1906d5fb>2012-12-31 12:33:18 +0000
commit4c95700fc6848d46a33b565df7eb81ada2b32987 (patch)
treea0f13e7a70f2e22516b9fae6177e7e8b7af269fe /FTNoIR_Tracker_PT/timer.cpp
parent977f25772f449e79089059820453bb7499ff4d35 (diff)
Updated PointTracker
git-svn-id: svn+ssh://svn.code.sf.net/p/facetracknoir/code@200 19e81ba0-9b1a-49c3-bd6c-561e1906d5fb
Diffstat (limited to 'FTNoIR_Tracker_PT/timer.cpp')
-rw-r--r--FTNoIR_Tracker_PT/timer.cpp66
1 files changed, 66 insertions, 0 deletions
diff --git a/FTNoIR_Tracker_PT/timer.cpp b/FTNoIR_Tracker_PT/timer.cpp
new file mode 100644
index 00000000..363b5b09
--- /dev/null
+++ b/FTNoIR_Tracker_PT/timer.cpp
@@ -0,0 +1,66 @@
+/* Copyright (c) 2012 Patrick Ruoff
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ */
+
+#include "timer.h"
+
+#include <stdlib.h>
+
+// ----------------------------------------------------------------------------
+Timer::Timer()
+: startTime(0), endTime(0), running(false)
+{
+#ifdef WIN32
+ QueryPerformanceFrequency(&frequency);
+ startCount.QuadPart = 0;
+ endCount.QuadPart = 0;
+#else
+ startCount.tv_sec = startCount.tv_usec = 0;
+ endCount.tv_sec = endCount.tv_usec = 0;
+#endif
+}
+
+
+void Timer::start()
+{
+#ifdef WIN32
+ QueryPerformanceCounter(&startCount);
+#else
+ gettimeofday(&startCount, NULL);
+#endif
+ running = true;
+}
+
+
+void Timer::stop()
+{
+#ifdef WIN32
+ QueryPerformanceCounter(&endCount);
+#else
+ gettimeofday(&endCount, NULL);
+#endif
+ running = false;
+}
+
+
+double Timer::elapsed()
+{
+#ifdef WIN32
+ if (running)
+ QueryPerformanceCounter(&endCount);
+
+ startTime = startCount.QuadPart * (1e3 / frequency.QuadPart);
+ endTime = endCount.QuadPart * (1e3 / frequency.QuadPart);
+#else
+ if(!stopped)
+ gettimeofday(&endCount, NULL);
+
+ startTime = (startCount.tv_sec * 1e3) + startCount.tv_usec;
+ endTime = (endCount.tv_sec * 1e3) + endCount.tv_usec;
+#endif
+
+ return endTime - startTime;
+} \ No newline at end of file