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) 25 #include <sys/times.h> 33 #if defined(CRYPTOPP_WIN32_AVAILABLE) 34 static TimerWord InitializePerformanceCounterFrequency()
36 LARGE_INTEGER freq = {0,0};
37 if (!QueryPerformanceFrequency(&freq))
42 inline TimerWord PerformanceCounterFrequency()
44 static const word64 freq = InitializePerformanceCounterFrequency();
49 #ifndef CRYPTOPP_IMPORTS 51 double 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;
119 #endif // #ifndef CRYPTOPP_IMPORTS 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);
140 GetCurrentThreadNotImplemented:
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.
Utility functions for the Crypto++ library.
word64 TimerWord
TimerWord is a 64-bit word.
unsigned long ElapsedTime()
Retrieve the elapsed time.
Some other error occurred not belonging to other categories.
TimerWord TicksPerSecond()
Retrieve ticks per second.
void StartTimer()
Start the timer.
virtual TimerWord TicksPerSecond()=0
Retrieve ticks per second.
TimerWord GetCurrentTimerValue()
Retrieve the current timer value.
unsigned long long word64
64-bit unsigned datatype
virtual TimerWord GetCurrentTimerValue()=0
Retrieve the current timer value.
#define COUNTOF(arr)
Counts elements in an array.
TimerWord GetCurrentTimerValue()
Retrieve the current timer value.
#define CRYPTOPP_ASSERT(exp)
Debugging and diagnostic assertion.
TimerWord TicksPerSecond()
Retrieve ticks per second.
double ElapsedTimeAsDouble()
Retrieve the elapsed time.
Debugging and diagnostic assertions.
std::string IntToString(T value, unsigned int base=10)
Converts a value to a string.
Crypto++ library namespace.