Index: third_party/qcms/src/tests/timing.h |
diff --git a/third_party/qcms/src/tests/timing.h b/third_party/qcms/src/tests/timing.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..83f1bbdf0cdfaa23d84b2bb0386fd39059ea46af |
--- /dev/null |
+++ b/third_party/qcms/src/tests/timing.h |
@@ -0,0 +1,51 @@ |
+// Copyright 2015 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the Chromium LICENSE file. |
+ |
+#ifndef TESTS_TIMING_H |
+#define TESTS_TIMING_H |
+ |
+#include <assert.h> |
+#if defined(_WIN32) |
+#include <windows.h> |
+#else |
+#include <sys/time.h> |
+#endif |
+#include <time.h> |
+ |
+#if defined(_WIN32) |
+ |
+static double seconds() |
+{ |
+ static double clock_frequency; |
+ static bool have_frequency; |
+ |
+ LARGE_INTEGER qpc; |
+ QueryPerformanceCounter(&qpc); |
+ if (have_frequency) |
+ return qpc.QuadPart * clock_frequency; |
+ |
+ have_frequency = true; |
+ QueryPerformanceFrequency(&qpc); |
+ clock_frequency = 1.0 / (double) qpc.QuadPart; |
+ return seconds(); |
+} |
+ |
+#else |
+ |
+static double seconds() |
+{ |
+ struct timeval now; |
+ gettimeofday(&now, 0); |
+ return now.tv_sec + now.tv_usec * (1.0 / 1000000.0); |
+} |
+ |
+#endif |
+ |
+#define TIME(function, time) do { \ |
+ double start = seconds(); \ |
+ (function); \ |
+ *time += seconds() - start; \ |
+} while (0) |
+ |
+#endif // TESTS_TIMING_H |