0


I'm trying to profile a function in another method, so in order to measure its time, I'm doing something like this:

double diffTime = GetCurrentTime() - m_lastTime;
SuspendOtherProcessThreads();
double runningTime += diffTime;

... Do profiling stuff ... 

ResumeOtherProcessThreads();
m_lastTime = GetCurrentTime();  

... Let profiled process run ....

This is what I do each sample and I consider the time in which I sampled to be "runningTime". But for some reason I get that "runningTime" is much smaller than the actual running time.
This code runs tens of thousands times a second.

does anybody know what's wrong with it?
does it have something to do with the Suspend/ Resume things?
thanks :)

Idov
  • 5,006
  • 17
  • 69
  • 106
  • 1
    There's nothing obviously wrong, but you're not giving us enough information to go on. it could be roundoff error if `diffTime` is too small, or maybe the profiling stuff takes more time than you think, or maybe you're measuring "actual running time" wrong, there's just no way to tell. – Beta Jan 01 '11 at 16:47
  • Profiling has multiple meanings. Are you only interested in measuring the amount of time it takes, or are you also interested in finding out which code points would be fruitful to optimize? Those are different tasks. – Mike Dunlavey Jan 01 '11 at 17:50
  • Beta - I'm not measuring the profiling time, but the "non-profiling" time. Mike - just the points that take the most time. :) – Idov Jan 01 '11 at 19:33
  • 1
    If your real concern is to find code points where you can optimize, to make the code run faster, it might seem strange, but that is very different from measuring. [Take a look at this.](http://stackoverflow.com/questions/4468022/how-to-measure/4501805#4501805) – Mike Dunlavey Jan 01 '11 at 20:10

1 Answers1

0

If your process is blocked by another process, your timing will be wrong.

Why are you not using a tool (like cachegrind to profile?

BЈовић
  • 62,405
  • 41
  • 173
  • 273