First public contribution.
2 * Portions Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
7 * This material is provided "as is", with absolutely no warranty expressed
8 * or implied. Any use is at your own risk.
10 * Permission to use or copy this software for any purpose is hereby granted
11 * without fee, provided the above notices are retained on all copies.
12 * Permission to modify the code and to distribute modified code is granted,
13 * provided the above notices are retained, and a notice that the code was
14 * modified is included with the above copyright notice.
18 #ifndef CPPUNIT_TIMER_H
19 #define CPPUNIT_TIMER_H
23 # define CPPUNIT_WIN32_TIMER
31 #if defined (CPPUNIT_WIN32_TIMER)
32 m_start.LowPart = m_restart.LowPart = m_stop.LowPart = 0;
33 m_start.HighPart = m_restart.HighPart = m_stop.HighPart = 0;
34 QueryPerformanceFrequency(&m_frequency);
39 #if defined (CPPUNIT_WIN32_TIMER)
40 QueryPerformanceCounter(&m_start);
45 #if defined (CPPUNIT_WIN32_TIMER)
46 QueryPerformanceCounter(&m_restart);
47 if (m_start.HighPart == 0 && m_start.LowPart == 0) {
54 #if defined (CPPUNIT_WIN32_TIMER)
56 QueryPerformanceCounter(&stop);
57 if ((m_stop.HighPart != 0 || m_stop.LowPart != 0) &&
58 m_restart.HighPart != 0 && m_restart.LowPart != 0) {
59 m_stop.HighPart += (stop.HighPart - m_restart.HighPart);
60 if (stop.LowPart < m_restart.LowPart) {
61 if (m_restart.LowPart - stop.LowPart > m_stop.LowPart) {
64 m_stop.LowPart -= m_restart.LowPart - stop.LowPart;
67 if (stop.LowPart - m_restart.LowPart > 0xFFFFFFFF - m_stop.LowPart) {
70 m_stop.LowPart += stop.LowPart - m_restart.LowPart;
79 double elapsedMilliseconds() const {
80 #if defined (CPPUNIT_WIN32_TIMER)
81 LARGE_INTEGER elapsed;
82 elapsed.HighPart = m_stop.HighPart - m_start.HighPart;
83 elapsed.LowPart = m_stop.LowPart - m_start.LowPart;
84 return (double)elapsed.QuadPart / (double)m_frequency.QuadPart * 1000;
90 static bool supported() {
91 #if defined (CPPUNIT_WIN32_TIMER)
99 #if defined (CPPUNIT_WIN32_TIMER)
100 LARGE_INTEGER m_frequency;
101 LARGE_INTEGER m_start, m_stop, m_restart;