Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdint.h>
- #include <stdio.h>
- #include <windows.h>
- using namespace std;
- // the function f() does some time-consuming work
- void f ()
- {
- volatile double d = 0;
- for (int n = 0; n < 25000; ++n)
- for (int m = 0; m < 100000; ++m)
- d += d * n * m;
- }
- int main ()
- {
- HANDLE hProcess;
- hProcess = GetCurrentProcess ();
- FILETIME CreationTime;
- FILETIME ExitTime;
- FILETIME KernelTime;
- FILETIME UserTime;
- f ();
- GetProcessTimes (hProcess, &CreationTime, &ExitTime, &KernelTime, &UserTime);
- uint64_t kernel = ((uint64_t) KernelTime.dwHighDateTime << 32) |
- KernelTime.dwLowDateTime;
- uint64_t user = ((uint64_t) UserTime.dwHighDateTime << 32) |
- UserTime.dwLowDateTime;
- printf ("%.0lf ms + %.0lf ms ~ %.0lf ms\n",
- kernel / 10000.0, user / 10000.0, (kernel + user) / 10000.0);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment