10#if defined(CRYPTOPP_WIN32_AVAILABLE)
11#define WIN32_LEAN_AND_MEAN
13# if ((WINVER >= 0x0602 ) || (_WIN32_WINNT >= 0x0602 ))
14# include <processthreadsapi.h>
15# if defined(WINAPI_FAMILY)
16# if (WINAPI_FAMILY_PARTITION(WINAPI_FAMILY_PHONE_APP))
17# include <profileapi.h>
23#if defined(CRYPTOPP_UNIX_AVAILABLE)
33#if defined(CRYPTOPP_WIN32_AVAILABLE)
34static TimerWord InitializePerformanceCounterFrequency()
36 LARGE_INTEGER freq = {0,0};
37 if (!QueryPerformanceFrequency(&freq))
42inline TimerWord PerformanceCounterFrequency()
44 static const word64 freq = InitializePerformanceCounterFrequency();
49#ifndef CRYPTOPP_IMPORTS
51double TimerBase::ConvertTo(
TimerWord t, Unit unit)
53 static unsigned long unitsPerSecondTable[] = {1, 1000, 1000*1000, 1000*1000*1000};
57 return static_cast<double>(t) * unitsPerSecondTable[unit] /
TicksPerSecond();
76 return ConvertTo(m_last - m_start, m_timerUnit);
87 return (
unsigned long)elapsed;
92#if defined(CRYPTOPP_WIN32_AVAILABLE)
94 LARGE_INTEGER now = {0,0};
95 if (!QueryPerformanceCounter(&now))
98#elif defined(CRYPTOPP_UNIX_AVAILABLE)
100 gettimeofday(&now, NULLPTR);
101 return (
TimerWord)now.tv_sec * 1000000 + now.tv_usec;
110#if defined(CRYPTOPP_WIN32_AVAILABLE)
111 return PerformanceCounterFrequency();
112#elif defined(CRYPTOPP_UNIX_AVAILABLE)
115 return CLOCKS_PER_SEC;
123#if defined(CRYPTOPP_WIN32_AVAILABLE) && defined(THREAD_TIMER_AVAILABLE)
124 static bool getCurrentThreadImplemented =
true;
125 if (getCurrentThreadImplemented)
127 FILETIME now, ignored;
128 if (!GetThreadTimes(GetCurrentThread(), &ignored, &ignored, &ignored, &now))
130 const DWORD lastError = GetLastError();
131 if (lastError == ERROR_CALL_NOT_IMPLEMENTED)
133 getCurrentThreadImplemented =
false;
134 goto GetCurrentThreadNotImplemented;
138 return now.dwLowDateTime + ((
TimerWord)now.dwHighDateTime << 32);
140GetCurrentThreadNotImplemented:
141 return (
TimerWord)clock() * (10*1000*1000 / CLOCKS_PER_SEC);
142#elif defined(CRYPTOPP_WIN32_AVAILABLE) && !defined(THREAD_TIMER_AVAILABLE)
144 if (!QueryPerformanceCounter(&now))
146 const DWORD lastError = GetLastError();
150#elif defined(CRYPTOPP_UNIX_AVAILABLE)
153 return now.tms_utime;
161#if defined(CRYPTOPP_WIN32_AVAILABLE) && defined(THREAD_TIMER_AVAILABLE)
163#elif defined(CRYPTOPP_WIN32_AVAILABLE) && !defined(THREAD_TIMER_AVAILABLE)
164 static const TimerWord ticksPerSecond = PerformanceCounterFrequency();
165 return ticksPerSecond;
166#elif defined(CRYPTOPP_UNIX_AVAILABLE)
167 static const long ticksPerSecond = sysconf(_SC_CLK_TCK);
168 return ticksPerSecond;
170 return CLOCKS_PER_SEC;
Base class for all exceptions thrown by the library.
@ OTHER_ERROR
Some other error occurred not belonging to other categories.
TimerWord GetCurrentTimerValue()
Retrieve the current timer value.
TimerWord TicksPerSecond()
Retrieve ticks per second.
double ElapsedTimeAsDouble()
Retrieve the elapsed time.
void StartTimer()
Start the timer.
virtual TimerWord TicksPerSecond()=0
Retrieve ticks per second.
virtual TimerWord GetCurrentTimerValue()=0
Retrieve the current timer value.
unsigned long ElapsedTime()
Retrieve the elapsed time.
TimerWord GetCurrentTimerValue()
Retrieve the current timer value.
TimerWord TicksPerSecond()
Retrieve ticks per second.
unsigned long long word64
64-bit unsigned datatype
word64 TimerWord
TimerWord is a 64-bit word.
Utility functions for the Crypto++ library.
#define COUNTOF(arr)
Counts elements in an array.
std::string IntToString(T value, unsigned int base=10)
Converts a value to a string.
Crypto++ library namespace.
Debugging and diagnostic assertions.
#define CRYPTOPP_ASSERT(exp)
Debugging and diagnostic assertion.