LARGE_INTEGER Freq;QueryPerformanceFrequency(&Freq); LARGE_INTEGER Start, End;QueryPerformanceCounter(&Start);// здесь идут вызовы, скорость которых мы меряемQueryPerformanceCounter(&End);cout << " Time: " << (float(End.QuadPart - Start.QuadPart)/Freq.QuadPart) << " second(s)" << endl;
#include <windows.h>double SysInfo::threadCpuTime(){ __int64 creation64, exit64, kernel64, user64; int rc = GetThreadTimes (GetCurrentThread (), (FILETIME *) &creation64, (FILETIME *) &exit64, (FILETIME *) &kernel64, (FILETIME *) &user64); double kernel = 0, user = 0; if (rc) { kernel = kernel64 * 1.0e-7; user = user64 * 1.0e-7; } return kernel + user;} double SysInfo::processCpuTime(){ __int64 creation64, exit64, kernel64, user64; int rc = GetProcessTimes (GetCurrentProcess (), (FILETIME *) &creation64, (FILETIME *) &exit64, (FILETIME *) &kernel64, (FILETIME *) &user64); double kernel = 0, user = 0; if (rc) { kernel = kernel64 * 1.0e-7; user = user64 * 1.0e-7; } return kernel + user;}
#include <unistd.h>double SysInfo::threadCpuTime(){ timespec tp; clock_gettime(CLOCK_THREAD_CPUTIME_ID, &tp); return tp.tv_sec + tp.tv_nsec * 1.0e-9;} double SysInfo::processCpuTime(){ timespec tp; clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &tp); return tp.tv_sec + tp.tv_nsec * 1.0e-9;}
sysTime = processCpuTime();process.start(coder,arguments); if (process.waitForFinished(-1)) { sysTime2 = processCpuTime(); }