Conversion of C++ code from Linux to Windows

前端 未结 3 1846

I am new to C++ , I have a program in C++ written for Linux. I\'m trying to convert it to Windows. The code I have is:

struct Timer 
{  
    struct tms t[2];
            


        
3条回答
  •  难免孤独
    2021-01-21 00:59

    This is (an untested, but logically correct) drop in replacement. The usertime function returns in second resolution (as a double) so you need to divide by the required resolution.

    struct Timer
    {
       __int64 t[2];
    
       void Start()
       {
          QueryPerformanceCounter((LARGE_INTEGER*)&t[0]);
       }
    
       void Stop()
       {
          QueryPerformanceCounter((LARGE_INTEGER*)&t[1]);
       }
    
       double usertime()
       {
          __int64 freq;
          QueryPerformanceFrequency((LARGE_INTEGER*)&freq);
          return (double(t[1] - t[0])) / freq;
       }
    };
    

提交回复
热议问题