]> git.lyx.org Git - lyx.git/commitdiff
Add a WIN32 equivalent for gettimeofday
authorVincent van Ravesteijn <vfr@lyx.org>
Sun, 24 Mar 2013 12:35:44 +0000 (13:35 +0100)
committerVincent van Ravesteijn <vfr@lyx.org>
Sun, 24 Mar 2013 15:47:07 +0000 (16:47 +0100)
This function does not really returns the "time of day", but it will suffice to evaluate elapsed times.

src/support/pmprof.h

index 7cd2efcbfbfc1a349c5473d41992edee68f053c3..7f74fe2646836254f27190f783c14cbd924118fc 100644 (file)
 #ifndef PMPROF_H
 #define PMPROF_H
 
+#ifdef _WIN32
+#include <windows.h>
+#else
 #include <sys/time.h>
+#endif
 #include <iostream>
 
 /** How to use this trivial profiler:
 
  */
 
+#ifdef _WIN32
+
+/* This function does not really returns the "time of day",
+ * but it will suffice to evaluate elapsed times.
+ */
+int gettimeofday(struct timeval * tv, struct timezone * /*tz*/)
+{
+       LARGE_INTEGER frequency, t;
+       QueryPerformanceFrequency(&frequency);
+       QueryPerformanceCounter(&t);
+
+       tv->tv_sec = long(t.QuadPart / frequency.QuadPart);
+       tv->tv_usec = long((1000000.0 * (t.QuadPart % frequency.QuadPart)) / frequency.QuadPart);
+       return 0;
+}
+
+#endif // _WIN32
 
 /* Helper class for gathering data. Instantiate this as a static
  * variable, so that its destructor will be executed when the program
  * ends.
  */
+
 class PMProfStat {
 public:
        PMProfStat(char const * name)