1. 운영체제 종류 확인
2. Argument 패스용 함수 _SkipArg
3. 실행시간 측정 (GetSystemTime)
#include#include LPTSTR _SkipArg(LPCTSTR targv) { LPTSTR p = (LPTSTR)targv; while( *p != '\0' && *p != '\t' && *p != 0x20 ) p++; while( *p != '\0' && ( *p == '\t' || *p == 0x20 ) ) p++; return p; } int _tmain(int argc, LPTSTR argv[]){ STARTUPINFO StartUp; PROCESS_INFORMATION ProcInfo; union{ LONGLONG li; FILETIME ft; } CreateTime, ExitTime, ElapsedTime; FILETIME KernelTime, UserTime; SYSTEMTIME ElTiSys, KeTiSys, UsTiSys, StartTimeSys, ExitTimeSys; LPTSTR targv = _SkipArg(GetCommandLine()); OSVERSIONINFO OSVer; BOOL IsNT; HANDLE hProc; OSVer.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); GetVersionEx(&OSVer); IsNT = (OSVer.dwPlatformId == VER_PLATFORM_WIN32_NT); GetStartupInfo(&StartUp); GetSystemTime(&StartTimeSys); CreateProcess(NULL, targv, NULL, NULL, TRUE, NORMAL_PRIORITY_CLASS, NULL, NULL, &StartUp, &ProcInfo); DuplicateHandle(GetCurrentProcess(), ProcInfo.hProcess, GetCurrentProcess(), &hProc, PROCESS_QUERY_INFORMATION | SYNCHRONIZE, FALSE, 0); WaitForSingleObject(hProc, INFINITE); GetSystemTime(&ExitTimeSys); if(IsNT){ GetProcessTimes(hProc, &CreateTime.ft, &ExitTime.ft, &KernelTime, &UserTime); ElapsedTime.li = ExitTime.li - CreateTime.li; FileTimeToSystemTime(&ElapsedTime.ft, &ElTiSys); FileTimeToSystemTime(&CreateTime.ft, &KeTiSys); FileTimeToSystemTime(&UserTime, &UsTiSys); _tprintf( _T("Real Time : %02d:%02d:%02d:%03d\n"), ElTiSys.wHour, ElTiSys.wMinute, ElTiSys.wSecond, ElTiSys.wMilliseconds); _tprintf( _T("User Time : %02d:%02d:%02d:%03d\n"), UsTiSys.wHour, UsTiSys.wMinute, UsTiSys.wSecond, UsTiSys.wMilliseconds); _tprintf( _T("Sys Time : %02d:%02d:%02d:%03d\n"), KeTiSys.wHour, KeTiSys.wMinute, KeTiSys.wSecond, KeTiSys.wMilliseconds); } else { _tprintf( _T("not NT\n") ); } CloseHandle(ProcInfo.hThread); CloseHandle(ProcInfo.hProcess); CloseHandle(hProc); return 0; }
'Research > Source Repository' 카테고리의 다른 글
Variadic 매크로 (0) | 2014.06.16 |
---|---|
ThreadPool simple example (0) | 2013.11.03 |
Mutex - Event Simple Code (0) | 2013.10.10 |
simple critical section (0) | 2013.10.09 |
Windows System Programming (0) | 2013.07.10 |