• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 505
  • Last Modified:

Computing Program execution time?

How to compute execution time/Clock cycles in VC++ editor  for c or c++ programs?

Suggestion and hints on the same at the earliest would be helpful.

Sateesh Mandre.
0
SateeshMandre
Asked:
SateeshMandre
  • 3
  • 2
  • 2
  • +8
1 Solution
 
AlexVirochovskyCommented:
CPU usage: how find cpu usage for all (or some) process:
http://www.edm2.com/0607/cpu.html
0
 
AssafLavieCommented:
You can use the pseudo watch variable #clk to time the execution of the program between each trace. It's not as accurate or robust as the professional tools that do it, but it's usefull.

Define two watch variables:
@clk
and
@clk = 0

then, whenever you trace (hit f10, or f11, or stop at a break point) you'll see the time that's passed since the last trace in this watch. It's shows the time in microseconds i think.
0
 
SateeshMandreAuthor Commented:
Thanks for the quick suggestion, but i have already tried this solution earlier, but i am getting the minimum response of 10 milliseconds,

i.e i started the timer at the begining of the program and then checked it before the exit of the program which is giving me a result of 10 milliseconds, and when i put the code in a loop and executing it, i am getting values multiples of 0 milliseconds. The problem is, when i want to check the execution time of a single function, i checked the timediff after each function call, but am  getting 0 milliseconds.   So I want to know if there is any method, where i can check the execution time of the function with some code or tools.

Sateesh Mandre
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
AssafLavieCommented:
Are you saying that you've stepped over the function and it showed you 0 microseconds? That's hard to believe.
0
 
jacobkristensenCommented:
When I want to time some function, I usually put int the line:

long Start = timeGetTime();

In the beginning, and the line:

long Elapsed = timeGetTime() - Start;

in the end. Elapsed then represents the execution time...
0
 
SateeshMandreAuthor Commented:
Thanks for your suggestion, but i have already done this This is similer to previous suggestion I got.I want in terms of micro seconds.
Sateesh Mandre
0
 
jacobkristensenCommented:
Have you tried a high resolution timer?
fx by calling QueryPerformanceFrequency()
0
 
AlexVirochovskyCommented:
>>So I want to know if there is any method, where i can check the execution time of the function with
some code or tools
If you want some tool, try
TakInfo2000 from
www.iarsn.com
Frim this tool you know cpu,memory, priority,files ... of
every apps in system.
As I know, he(Igor Arsenin) uses methods ~ same as in my comment.
0
 
qbawler311Commented:
Windows can only measure to 10 milliseconds.  So if your function only took 4 milliseconds to do a loop.  It will read 0 milliseconds.  It's impossible to measure in microseconds, Windows isn't that accurate.
0
 
BlackDiamondCommented:
0
 
bkdcCommented:
I agree with qbawler311
M$ stuff:
"
The GetTickCount() API should not be used for resolution critical
algorythms. Instead, QueryPerformanceCounter() and
QueryPerformanceFrequency() should be used.

The Win32 API QueryPerformanceCounter() returns the resolution of a
high- resolution performance counter if the hardware supports one. For
x86, the resolution is about 0.8 microseconds (0.0008 ms). You need to
call QueryPerformanceFrequency() to get the frequency of the
high-resolution performance counter. "


void stuff()
{
  LARGE_INTEGER q,w,freq,overhead,sp,speed;
  if(QueryPerformanceCounter(q)) //long live 386 -won't work (in case you care)
  {
    QueryPerformanceCounter(q);
    QueryPerformanceCounter(w);
    overhead=w-q; //time taken by calls to the 2 funcs.
    QueryPerformanceCounter(q); //start ticking
       //your stuff comes here
    ...........
    //end of the routine to be clocked
    QueryPerformanceCounter(w); //no more ticking
    QueryPerformanceFrequency(freq);
    sp=w-q-overhead; //that's the speed in ticks
       speed=sp/freq;
    cout<<"Time taken:"<<speed;
   }
}
 
//some tweaking might be required, I don't have a Windows machine right now so... not tested (!!! hopefully won't harm your PC, pet or wife :) )
0
 
bkdcCommented:
>>It's impossible to measure in microseconds, Windows isn't that accurate.

Err..no quite right. It's true that the timer resolution is somewhere around 10ms (that's true on NT/2K, it's slightly different under 9x >=20ms, if you're "lucky" 50ms)
0
 
bkdcCommented:
SateeshMandre, one suggestion if I may...
Check out msdn.microsoft.com
Not a piece of art but the Knowledge Base it's worth every penny (and it won't cost you points nor time wasted while waiting for an answer from somebody)
0
 
BogdyPtrCommented:
On NT/2000 try GetProcessTimes api function
0
 
jcgdCommented:
Maybe this help you:
-------
GetSystemTimeAdjustment(&savedwTimeAdjustment,  &dwTimeIncrement,   &bTimeAdjustmentDisabled);
GetSystemTime(  lpSystemTime );
dwTimeIncrement *= 100;
SetSystemTimeAdjustment(dwTimeIncrement ,FALSE);
func();    
SetSystemTimeAdjustment(savedwTimeAdjustment,TRUE);
GetSystemTime(  lpSystemTime2);
-------
SetSystemTimeAdjustment (first) add dwTimeIncrement for each clock interrupt to time-of-day.

0
 
griesshCommented:
I think you forgot this question. I will ask Community Support to close it unless you finalize it within 7 days. Unless there is objection or further activity,  I will suggest to accept "jbawler311, BlackDiamond" comment(s) as an answer.

If you think your question was not answered at all, you can post a request in Community support (please include this link) to refund your points.
The link to the Community Support area is: http://www.experts-exchange.com/commspt

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
======
Werner
0
 
NetminderCommented:
Per recommendation, force-accepted by
Netminder
Community Support Moderator
Experts Exchange

qbawler311: points for you at http://www.experts-exchange.com/jsp/qShow.jsp?ta=cplusprog&qid=20279971
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 3
  • 2
  • 2
  • +8
Tackle projects and never again get stuck behind a technical roadblock.
Join Now