Browse Source

Get seconds using high resolution performance counter (Windows only).

Former-commit-id: e761ea3e11f6ba53661a2ff74e92a660738ac457
kavanl 13 years ago
parent
commit
cc6f68da7c
1 changed files with 31 additions and 0 deletions
  1. 31 0
      get_seconds_hires.h

+ 31 - 0
get_seconds_hires.h

@@ -0,0 +1,31 @@
+#ifndef IGL_GET_SECONDS_HIRES_H
+#define IGL_GET_SECONDS_HIRES_H
+
+namespace igl
+{
+	// Return the current time in seconds using performance counters
+	inline double get_seconds_hires();
+}
+
+//Implementation
+#if _WIN32
+#  include <windows.h>
+inline double igl::get_seconds_hires()
+{
+	LARGE_INTEGER li_freq, li_current;
+	const bool ret = QueryPerformanceFrequency(&li_freq);
+	const bool ret2 = QueryPerformanceCounter(&li_current);
+	assert(ret && ret2);
+	assert(li_freq.QuadPart > 0);
+	return double(li_current.QuadPart) / double(li_freq.QuadPart);
+}
+#else
+#  include <sys/time.h>
+inline double igl::get_seconds_hires()
+{
+	// Sorry I've no idea how performance counters work on Mac...
+	assert(false);
+	return 0.0;
+}
+#endif
+#endif