1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/genericopenlibs/cppstdlib/stl/test/unit/cppunit/cppunit_timer.h Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,105 @@
1.4 +/*
1.5 + * Portions Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
1.6 + *
1.7 + * Copyright (c) 2006
1.8 + * Francois Dumont
1.9 + *
1.10 + * This material is provided "as is", with absolutely no warranty expressed
1.11 + * or implied. Any use is at your own risk.
1.12 + *
1.13 + * Permission to use or copy this software for any purpose is hereby granted
1.14 + * without fee, provided the above notices are retained on all copies.
1.15 + * Permission to modify the code and to distribute modified code is granted,
1.16 + * provided the above notices are retained, and a notice that the code was
1.17 + * modified is included with the above copyright notice.
1.18 + *
1.19 + */
1.20 +
1.21 +#ifndef CPPUNIT_TIMER_H
1.22 +#define CPPUNIT_TIMER_H
1.23 +
1.24 +#ifndef __SYMBIAN32__
1.25 +#if defined (_WIN32)
1.26 +# define CPPUNIT_WIN32_TIMER
1.27 +# include <windows.h>
1.28 +#endif
1.29 +#endif
1.30 +
1.31 +class Timer {
1.32 +public:
1.33 + Timer() {
1.34 +#if defined (CPPUNIT_WIN32_TIMER)
1.35 + m_start.LowPart = m_restart.LowPart = m_stop.LowPart = 0;
1.36 + m_start.HighPart = m_restart.HighPart = m_stop.HighPart = 0;
1.37 + QueryPerformanceFrequency(&m_frequency);
1.38 +#endif
1.39 + }
1.40 +
1.41 + void start() {
1.42 +#if defined (CPPUNIT_WIN32_TIMER)
1.43 + QueryPerformanceCounter(&m_start);
1.44 +#endif
1.45 + }
1.46 +
1.47 + void restart() {
1.48 +#if defined (CPPUNIT_WIN32_TIMER)
1.49 + QueryPerformanceCounter(&m_restart);
1.50 + if (m_start.HighPart == 0 && m_start.LowPart == 0) {
1.51 + m_start = m_restart;
1.52 + }
1.53 +#endif
1.54 + }
1.55 +
1.56 + void stop() {
1.57 +#if defined (CPPUNIT_WIN32_TIMER)
1.58 + LARGE_INTEGER stop;
1.59 + QueryPerformanceCounter(&stop);
1.60 + if ((m_stop.HighPart != 0 || m_stop.LowPart != 0) &&
1.61 + m_restart.HighPart != 0 && m_restart.LowPart != 0) {
1.62 + m_stop.HighPart += (stop.HighPart - m_restart.HighPart);
1.63 + if (stop.LowPart < m_restart.LowPart) {
1.64 + if (m_restart.LowPart - stop.LowPart > m_stop.LowPart) {
1.65 + m_stop.HighPart -= 1;
1.66 + }
1.67 + m_stop.LowPart -= m_restart.LowPart - stop.LowPart;
1.68 + }
1.69 + else {
1.70 + if (stop.LowPart - m_restart.LowPart > 0xFFFFFFFF - m_stop.LowPart) {
1.71 + m_stop.HighPart += 1;
1.72 + }
1.73 + m_stop.LowPart += stop.LowPart - m_restart.LowPart;
1.74 + }
1.75 + }
1.76 + else {
1.77 + m_stop = stop;
1.78 + }
1.79 +#endif
1.80 + }
1.81 +
1.82 + double elapsedMilliseconds() const {
1.83 +#if defined (CPPUNIT_WIN32_TIMER)
1.84 + LARGE_INTEGER elapsed;
1.85 + elapsed.HighPart = m_stop.HighPart - m_start.HighPart;
1.86 + elapsed.LowPart = m_stop.LowPart - m_start.LowPart;
1.87 + return (double)elapsed.QuadPart / (double)m_frequency.QuadPart * 1000;
1.88 +#else
1.89 + return 0;
1.90 +#endif
1.91 + }
1.92 +
1.93 + static bool supported() {
1.94 +#if defined (CPPUNIT_WIN32_TIMER)
1.95 + return true;
1.96 +#else
1.97 + return false;
1.98 +#endif
1.99 + }
1.100 +
1.101 +private:
1.102 +#if defined (CPPUNIT_WIN32_TIMER)
1.103 + LARGE_INTEGER m_frequency;
1.104 + LARGE_INTEGER m_start, m_stop, m_restart;
1.105 +#endif
1.106 +};
1.107 +
1.108 +#endif