From 10e201d961537c84aefb3922dd3b68838daf77ab Mon Sep 17 00:00:00 2001
From: Thomas Fischer <thomas.fischer@ufz.de>
Date: Tue, 11 Oct 2011 15:16:29 +0200
Subject: [PATCH] made time measurement in windows working

---
 Base/RunTimeTimer.cpp                  | 13 ++++++++++++-
 Base/RunTimeTimer.h                    | 20 +++++++++++++++-----
 SimpleTests/MatrixTests/CMakeLists.txt |  4 ++++
 SimpleTests/SolverTests/CMakeLists.txt | 12 ++++++++++++
 4 files changed, 43 insertions(+), 6 deletions(-)

diff --git a/Base/RunTimeTimer.cpp b/Base/RunTimeTimer.cpp
index b8956324566..10599073b8e 100644
--- a/Base/RunTimeTimer.cpp
+++ b/Base/RunTimeTimer.cpp
@@ -2,16 +2,27 @@
 
 void RunTimeTimer::start()
 {
+#ifndef _WIN32
 	gettimeofday(&_start, 0);
+#else
+	_start = timeGetTime();
+#endif
 }
 
 void RunTimeTimer::stop()
 {
+#ifndef _WIN32
 	gettimeofday(&_stop, 0);
+#else
+	_stop = timeGetTime();
+#endif
 }
 
 double RunTimeTimer::elapsed()
 {
+#ifndef _WIN32
 	return (_stop.tv_sec + _stop.tv_usec/1000000.0 - (_start.tv_sec + _start.tv_usec/1000000.0));
+#else
+	return (_stop - _start) / 1000;
+#endif
 }
-
diff --git a/Base/RunTimeTimer.h b/Base/RunTimeTimer.h
index 871cfb5a601..ebd7d858d6f 100644
--- a/Base/RunTimeTimer.h
+++ b/Base/RunTimeTimer.h
@@ -1,21 +1,31 @@
 #ifndef RUNTIMETIMER_H
 #define RUNTIMETIMER_H
 
+#include "TimeMeasurementBase.h"
+
+#ifndef _WIN32
 #include <sys/time.h>
+#else
+#include <windows.h>
+#endif
 
 #include "TimeMeasurementBase.h"
 
-class RunTimeTimer
+class RunTimeTimer : public TimeMeasurementBase
 {
 public:
-        virtual void start();
-        virtual void stop();
-        virtual double elapsed();
+	virtual void start();
+	virtual void stop();
+	virtual double elapsed();
 	~RunTimeTimer() {};
 private:
+#ifndef _WIN32
 	timeval _start;
 	timeval _stop;
+#else
+	unsigned long _start;
+	unsigned long _stop;
+#endif
 };
 
 #endif
-
diff --git a/SimpleTests/MatrixTests/CMakeLists.txt b/SimpleTests/MatrixTests/CMakeLists.txt
index 08a920431b8..bda3c0ca41a 100644
--- a/SimpleTests/MatrixTests/CMakeLists.txt
+++ b/SimpleTests/MatrixTests/CMakeLists.txt
@@ -19,6 +19,10 @@ ADD_EXECUTABLE( MatMult
         ${HEADERS}
 )
 
+IF (WIN32)
+        TARGET_LINK_LIBRARIES(MatMult Winmm.lib)
+ENDIF (WIN32)
+
 TARGET_LINK_LIBRARIES ( MatMult
 	Base
 	MathLib
diff --git a/SimpleTests/SolverTests/CMakeLists.txt b/SimpleTests/SolverTests/CMakeLists.txt
index ef3aa2f0c06..1c5784a7e1a 100644
--- a/SimpleTests/SolverTests/CMakeLists.txt
+++ b/SimpleTests/SolverTests/CMakeLists.txt
@@ -44,6 +44,9 @@ ADD_EXECUTABLE( GMResDiagPrecond
 )
 
 
+IF (WIN32)
+        TARGET_LINK_LIBRARIES(ConjugateGradientUnpreconditioned Winmm.lib)
+ENDIF (WIN32)
 TARGET_LINK_LIBRARIES ( ConjugateGradientUnpreconditioned
         ${BLAS_LIBRARIES}
         ${LAPACK_LIBRARIES}
@@ -51,6 +54,9 @@ TARGET_LINK_LIBRARIES ( ConjugateGradientUnpreconditioned
 	Base
 )
 
+IF (WIN32)
+        TARGET_LINK_LIBRARIES(ConjugateGradientDiagPrecond Winmm.lib)
+ENDIF (WIN32)
 TARGET_LINK_LIBRARIES ( ConjugateGradientDiagPrecond
         ${BLAS_LIBRARIES}
         ${LAPACK_LIBRARIES}
@@ -58,6 +64,9 @@ TARGET_LINK_LIBRARIES ( ConjugateGradientDiagPrecond
 	Base
 )
 
+IF (WIN32)
+        TARGET_LINK_LIBRARIES(BiCGStabDiagPrecond Winmm.lib)
+ENDIF (WIN32)
 TARGET_LINK_LIBRARIES( BiCGStabDiagPrecond
         ${BLAS_LIBRARIES}
         ${LAPACK_LIBRARIES}
@@ -65,6 +74,9 @@ TARGET_LINK_LIBRARIES( BiCGStabDiagPrecond
 	Base
 )
 
+IF (WIN32)
+        TARGET_LINK_LIBRARIES(GMResDiagPrecond Winmm.lib)
+ENDIF (WIN32)
 TARGET_LINK_LIBRARIES( GMResDiagPrecond
         ${BLAS_LIBRARIES}
         ${LAPACK_LIBRARIES}
-- 
GitLab