← Back to team overview

kicad-developers team mailing list archive

[PATCH 08/12] windows: provide performance measurement primitives

 

On Windows, performance measurement is best performed using
QueryPerformanceCounter, which reports ticks with an arbitrary but fixed
frequency.
---
 include/profile.h | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

diff --git a/include/profile.h b/include/profile.h
index acf9166..94ad40e 100644
--- a/include/profile.h
+++ b/include/profile.h
@@ -30,6 +30,7 @@
 #ifndef __TPROFILE_H
 #define __TPROFILE_H
 
+#ifndef _WIN32
 #include <sys/time.h>
 #include <stdint.h>
 
@@ -87,4 +88,35 @@ static inline void prof_end( prof_counter* aCnt )
     aCnt->end = get_tics();
 }
 
+#else
+
+#include <windows.h>
+
+struct prof_counter
+{
+    prof_counter() { freq.QuadPart = 0; }
+    LARGE_INTEGER start, end;
+    mutable LARGE_INTEGER freq;
+
+    float msecs() const
+    {
+        if( freq.QuadPart == 0 )
+            ::QueryPerformanceFrequency( &freq );
+
+        return (float)(end.QuadPart - start.QuadPart) * 1000 / freq.QuadPart;
+    }
+};
+
+static inline void prof_start( prof_counter* aCnt )
+{
+    ::QueryPerformanceCounter( &aCnt->start );
+}
+
+static inline void prof_end( prof_counter* aCnt )
+{
+    ::QueryPerformanceCounter( &aCnt->end );
+}
+
+#endif
+
 #endif

Follow ups

References