2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved.
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
11 #ifndef VPX_PORTS_VPX_TIMER_H_
12 #define VPX_PORTS_VPX_TIMER_H_
14 #include "./vpx_config.h"
16 #include "vpx/vpx_integer.h"
22 * Win32 specific includes
26 #ifndef WIN32_LEAN_AND_MEAN
27 #define WIN32_LEAN_AND_MEAN
32 * POSIX specific includes
36 /* timersub is not provided by msys at this time. */
38 #define timersub(a, b, result) \
40 (result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \
41 (result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \
42 if ((result)->tv_usec < 0) { \
44 (result)->tv_usec += 1000000; \
50 struct vpx_usec_timer {
52 LARGE_INTEGER begin, end;
54 struct timeval begin, end;
58 static INLINE void vpx_usec_timer_start(struct vpx_usec_timer *t) {
60 QueryPerformanceCounter(&t->begin);
62 gettimeofday(&t->begin, NULL);
66 static INLINE void vpx_usec_timer_mark(struct vpx_usec_timer *t) {
68 QueryPerformanceCounter(&t->end);
70 gettimeofday(&t->end, NULL);
74 static INLINE int64_t vpx_usec_timer_elapsed(struct vpx_usec_timer *t) {
76 LARGE_INTEGER freq, diff;
78 diff.QuadPart = t->end.QuadPart - t->begin.QuadPart;
80 QueryPerformanceFrequency(&freq);
81 return diff.QuadPart * 1000000 / freq.QuadPart;
85 timersub(&t->end, &t->begin, &diff);
86 return (int64_t)diff.tv_sec * 1000000 + diff.tv_usec;
90 #else /* CONFIG_OS_SUPPORT = 0*/
92 /* Empty timer functions if CONFIG_OS_SUPPORT = 0 */
94 #define timersub(a, b, result)
97 struct vpx_usec_timer {
101 static INLINE void vpx_usec_timer_start(struct vpx_usec_timer *t) {}
103 static INLINE void vpx_usec_timer_mark(struct vpx_usec_timer *t) {}
105 static INLINE int vpx_usec_timer_elapsed(struct vpx_usec_timer *t) { return 0; }
107 #endif /* CONFIG_OS_SUPPORT */
109 #endif // VPX_PORTS_VPX_TIMER_H_