Solved

Computing Program execution time?

Posted on 2001-08-28
17
496 Views
Last Modified: 2008-02-26
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
Comment
Question by:SateeshMandre
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +8
17 Comments
 
LVL 14

Expert Comment

by:AlexVirochovsky
ID: 6435244
CPU usage: how find cpu usage for all (or some) process:
http://www.edm2.com/0607/cpu.html
0
 
LVL 4

Expert Comment

by:AssafLavie
ID: 6435488
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
 

Author Comment

by:SateeshMandre
ID: 6435522
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 4

Expert Comment

by:AssafLavie
ID: 6435544
Are you saying that you've stepped over the function and it showed you 0 microseconds? That's hard to believe.
0
 
LVL 1

Expert Comment

by:jacobkristensen
ID: 6435739
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
 

Author Comment

by:SateeshMandre
ID: 6435778
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
 
LVL 1

Expert Comment

by:jacobkristensen
ID: 6435798
Have you tried a high resolution timer?
fx by calling QueryPerformanceFrequency()
0
 
LVL 14

Expert Comment

by:AlexVirochovsky
ID: 6435854
>>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
 

Expert Comment

by:qbawler311
ID: 6436900
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
 
LVL 5

Accepted Solution

by:
BlackDiamond earned 25 total points
ID: 6437970
0
 
LVL 2

Expert Comment

by:bkdc
ID: 6438425
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
 
LVL 2

Expert Comment

by:bkdc
ID: 6438432
>>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
 
LVL 2

Expert Comment

by:bkdc
ID: 6438448
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
 
LVL 2

Expert Comment

by:BogdyPtr
ID: 6442147
On NT/2000 try GetProcessTimes api function
0
 
LVL 3

Expert Comment

by:jcgd
ID: 6447009
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
 
LVL 11

Expert Comment

by:griessh
ID: 6862515
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
 
LVL 5

Expert Comment

by:Netminder
ID: 6886409
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question