Gassa

Measuring Time on Codeforces

Mar 12th, 2016
315
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.84 KB | None | 0 0
  1. #include <stdint.h>
  2. #include <stdio.h>
  3. #include <windows.h>
  4.  
  5. using namespace std;
  6.  
  7. // the function f() does some time-consuming work
  8. void f ()
  9. {
  10.   volatile double d = 0;
  11.   for (int n = 0; n < 25000; ++n)
  12.     for (int m = 0; m < 100000; ++m)
  13.       d += d * n * m;
  14. }
  15.  
  16. int main ()
  17. {
  18.   HANDLE hProcess;
  19.   hProcess = GetCurrentProcess ();
  20.   FILETIME CreationTime;
  21.   FILETIME ExitTime;
  22.   FILETIME KernelTime;
  23.   FILETIME UserTime;
  24.   f ();
  25.   GetProcessTimes (hProcess, &CreationTime, &ExitTime, &KernelTime, &UserTime);
  26.   uint64_t kernel = ((uint64_t) KernelTime.dwHighDateTime << 32) |
  27.     KernelTime.dwLowDateTime;
  28.   uint64_t user = ((uint64_t) UserTime.dwHighDateTime << 32) |
  29.     UserTime.dwLowDateTime;
  30.   printf ("%.0lf ms + %.0lf ms ~ %.0lf ms\n",
  31.     kernel / 10000.0, user / 10000.0, (kernel + user) / 10000.0);
  32.   return 0;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment