2 * Copyright (c) 2010 The VP8 project authors. All Rights Reserved.
4 * Use of this source code is governed by a BSD-style license and patent
5 * grant that can be found in the LICENSE file in the root of the source
6 * tree. All contributing project authors may be found in the AUTHORS
7 * file in the root of the source tree.
16 * Win32 specific includes
18 #ifndef WIN32_LEAN_AND_MEAN
19 #define WIN32_LEAN_AND_MEAN
24 * POSIX specific includes
28 /* timersub is not provided by msys at this time. */
30 #define timersub(a, b, result) \
32 (result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \
33 (result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \
34 if ((result)->tv_usec < 0) { \
36 (result)->tv_usec += 1000000; \
46 LARGE_INTEGER begin, end;
48 struct timeval begin, end;
54 vpx_usec_timer_start(struct vpx_usec_timer *t)
57 QueryPerformanceCounter(&t->begin);
59 gettimeofday(&t->begin, NULL);
65 vpx_usec_timer_mark(struct vpx_usec_timer *t)
68 QueryPerformanceCounter(&t->end);
70 gettimeofday(&t->end, NULL);
76 vpx_usec_timer_elapsed(struct vpx_usec_timer *t)
79 LARGE_INTEGER freq, diff;
81 diff.QuadPart = t->end.QuadPart - t->begin.QuadPart;
83 if (QueryPerformanceFrequency(&freq) && diff.QuadPart < freq.QuadPart)
84 return (long)(diff.QuadPart * 1000000 / freq.QuadPart);
90 timersub(&t->end, &t->begin, &diff);
91 return diff.tv_sec ? 1000000 : diff.tv_usec;