timethis
This is very small and handy C++ utility that will tells you about any command how long time it took to finish the execution or perform a simple DOS command along with user time and kernel time.
Example
c:\ExecTime.exe dir /s C:\
——————————–
Kernel Time 00:00:00:0000
User Time 00:00:00:0015
Creation Time 20:00:32:0734
Start Time 20:00:32:0749
End Time 20:00:32:0890
Elapsed Time 00:00:00:0141
——————————–
in above small example dir /s c:\ command took 141 mili seconds to execute.
Code Snippet
Here is small sample code snippet to print the time and this code is tested using Visual Studio 2012
struct myst:public SYSTEMTIME
{
myst& operator-(const myst& st)
{
myst t;
memset(&t,0,sizeof(t));
int ntempHour = 0;
if(st.wDay != wDay)
{
ntempHour = (wDay - st.wDay) * 24;
}
unsigned long nSmall = st.wMilliseconds + st.wSecond*1000 + st.wMinute*60*1000 + st.wHour*60*60*1000;
unsigned long nBig = wMilliseconds + wSecond*1000 + wMinute*60*1000 + (ntempHour + wHour)*60*60*1000;
unsigned long temp = nBig - nSmall;
while(temp)
{
if(temp > 999)
{
if(temp > 60*1000)
{
if(temp > 60*60*1000)
{
t.wHour++;
temp = temp - 60*60*1000;
}
else
{
t.wMinute++;
temp = temp - 60*1000;
}
}
else
{
t.wSecond++;
temp = temp - 1000;
}
}
else
{
t.wMilliseconds = temp;
temp = 0;
}
}
return t;
}
};
myst StartTime;
void main() {
GetSystemTime(&StartTime);
sprintf(csCurrentTime, "Start Time\t%02d:%02d:%02d:%04d", StartTime.wHour, StartTime.wMinute, StartTime.wSecond, StartTime.wMilliseconds );
system(str2.c_str());
printf("\n--------------------------------\n");
PrintKernelUserTime();
printf("\n--------------------------------\n");
}
NOTE: Read this post for PrintKernelUserTime() function
Question OR Feedback?
Note
If you want to ask anything related this post, please tweet your question or feedback @JangidUK I will try to respond as soon as possible.