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.
12 #ifndef VPX_PORTS_VPX_TIMER_H_
13 #define VPX_PORTS_VPX_TIMER_H_
14 #include "vpx/vpx_integer.h"
20 * Win32 specific includes
22 #ifndef WIN32_LEAN_AND_MEAN
23 #define WIN32_LEAN_AND_MEAN
28 * POSIX specific includes
32 /* timersub is not provided by msys at this time. */
34 #define timersub(a, b, result) \
36 (result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \
37 (result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \
38 if ((result)->tv_usec < 0) { \
40 (result)->tv_usec += 1000000; \
47 struct vpx_usec_timer {
49 LARGE_INTEGER begin, end;
51 struct timeval begin, end;
57 vpx_usec_timer_start(struct vpx_usec_timer *t) {
59 QueryPerformanceCounter(&t->begin);
61 gettimeofday(&t->begin, NULL);
67 vpx_usec_timer_mark(struct vpx_usec_timer *t) {
69 QueryPerformanceCounter(&t->end);
71 gettimeofday(&t->end, NULL);
77 vpx_usec_timer_elapsed(struct vpx_usec_timer *t) {
79 LARGE_INTEGER freq, diff;
81 diff.QuadPart = t->end.QuadPart - t->begin.QuadPart;
83 QueryPerformanceFrequency(&freq);
84 return diff.QuadPart * 1000000 / freq.QuadPart;
88 timersub(&t->end, &t->begin, &diff);
89 return diff.tv_sec * 1000000 + diff.tv_usec;
93 #else /* CONFIG_OS_SUPPORT = 0*/
95 /* Empty timer functions if CONFIG_OS_SUPPORT = 0 */
97 #define timersub(a, b, result)
100 struct vpx_usec_timer {
105 vpx_usec_timer_start(struct vpx_usec_timer *t) { }
108 vpx_usec_timer_mark(struct vpx_usec_timer *t) { }
111 vpx_usec_timer_elapsed(struct vpx_usec_timer *t) {
115 #endif /* CONFIG_OS_SUPPORT */
117 #endif // VPX_PORTS_VPX_TIMER_H_