Cayley
Pseudo-Random Bits from Finite Groups
CPUtime.cpp
Go to the documentation of this file.
1 
4 #include <cinttypes>
5 
6 #ifdef _MSC_VER //Windows Visual Studio
7 
8 #include <windows.h>
9 
12 
13 uint64_t CPUTimeInCentiNanoseconds(){
14  uint64_t result = 0; //return result
15  HANDLE h = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, GetCurrentProcessId());
16 
17  if(h){ //got process handle successfully
18  FILETIME ftCreation, ftExit, ftKernel, ftUser; //we only need ftUser
19 
20  if(GetProcessTimes(h, &ftCreation, &ftExit, &ftKernel, &ftUser)){
21  ULARGE_INTEGER t; //ULARGE_INTEGER avoids alignment problems in Win64
22  t.HighPart = ftUser.dwHighDateTime; //copy over ftUser to t
23  t.LowPart = ftUser.dwLowDateTime; //copy over ftUser to t
24 
25  result = t.QuadPart; //this apparently avoids endian problems
26  } //if
27 
28  CloseHandle(h); //done with process handle
29  } //if
30 
31  return result;
32 } //CPUTimeInCentiNanoseconds
33 
36 
37 uint64_t CPUTimeInNanoseconds(){
38  return 100LL*CPUTimeInCentiNanoseconds();
39 } //CPUTimeInNanoseconds
40 
41 #else//other OS
42 
43 #include <time.h>
44 
47 
49  return clock()*(1000000000LL/CLOCKS_PER_SEC);
50 } //CPUTimeInNanoseconds
51 
52 #endif
uint64_t CPUTimeInNanoseconds()
CPU time in nanoseconds.
Definition: CPUtime.cpp:48