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 #ifndef CRYPTOPP_IMPORTS 35 #if defined(CRYPTOPP_WIN32_AVAILABLE) 36 static TimerWord InitializePerformanceCounterFrequency()
38 LARGE_INTEGER freq = {0,0};
39 if (!QueryPerformanceFrequency(&freq))
44 inline TimerWord PerformanceCounterFrequency()
46 static const word64 freq = InitializePerformanceCounterFrequency();
53 static unsigned long unitsPerSecondTable[] = {1, 1000, 1000*1000, 1000*1000*1000};
57 return static_cast<double>(t) * unitsPerSecondTable[unit] /
TicksPerSecond();
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, NULL);
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:
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.
unsigned long ElapsedTime()
#define NAMESPACE_BEGIN(x)
Some other error occurred not belonging to other categories.
TimerWord TicksPerSecond()
virtual TimerWord TicksPerSecond()=0
TimerWord GetCurrentTimerValue()
virtual TimerWord GetCurrentTimerValue()=0
unsigned long long word64
TimerWord GetCurrentTimerValue()
double ConvertTo(TimerWord t, Unit unit)
#define CRYPTOPP_ASSERT(exp)
TimerWord TicksPerSecond()
double ElapsedTimeAsDouble()
Debugging and diagnostic assertions.
std::string IntToString(T value, unsigned int base=10)
Converts a value to a string.