瀏覽代碼

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

Former-commit-id: e761ea3e11f6ba53661a2ff74e92a660738ac457
kavanl 13 年之前
父節點
當前提交
cc6f68da7c
共有 1 個文件被更改,包括 31 次插入0 次删除
  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