-1

I have to measure the performance of a decoder in terms of number of frames decoded per second. i.e. calculating the FPS.

Below is what my code snippet looks like:

//global variables
clock_t start,stop;
double totTime, FPS;


main()
{
   while(End_of_file)
   {
      start=clock();

      //Decode function is called here

      stop=clock();

      totTime=stop-start;

      FPS=1/(totTime/CLOCKS_PER_SEC);

      printf("\n %lf fps\n",FPS);
   }
}

The printf statement sometimes prints proper value, however sometimes it gives a value 1.#INF00 which according to whatever i have searched is a floating point exception also called as positive infinity, which occurs when we try to divide a positive number by zero. So my question is why is it taking totTime=start-stop; being considered as 0 ? Second, if not clock(), then how do i get the time taken by the decode function.

Any suggestions regarding the same will be really helpful. Thanks in advance.

Zax
  • 2,870
  • 7
  • 52
  • 76
  • Are your 'normal' times (*not* FPS) very close to zero? Computers are fast, and the resolution of `clock` is rather low (1 millisecond on my system). In addition, there is bound to be lots of jittering (disk access, mouse movement, etc.). Try running your decode routine 1,000 or even more times. – Jongware Dec 30 '13 at 09:27
  • @Jongware: Thanks for your comment. So if its close to zero, then is there any other mechanism to check time taken to execute a function? – Zax Dec 30 '13 at 09:29
  • That would be the "Try running your decode routine 1,000 or even more times" part. – Jongware Dec 30 '13 at 09:41
  • But i need to calculate the time taken to run decode for each frame in the video. – Zax Dec 30 '13 at 09:46
  • Okay, so you are not looking for "profiling" but rather a "real-time" solution. Does this help? http://stackoverflow.com/questions/6749621/high-resolution-timer-in-linux – Jongware Dec 30 '13 at 09:50
  • clock_gettime() function is for linux. I'm working on windows. Any other way to measure execution time? – Zax Dec 30 '13 at 09:52
  • There is a Windows API for that too: http://stackoverflow.com/questions/5404277/porting-clock-gettime-to-windows – Jongware Dec 30 '13 at 09:58

1 Answers1

0

The proper macro for this is CLOCKS_PER_SEC, not CLOCK_PER_SEC.

Also, instead of using clock(), you can use clock_gettime() since you just want the time.

Josselin Poiret
  • 508
  • 3
  • 10
  • Sorry thats a typing mistake. Otherwise i would have got a compilation error. – Zax Dec 30 '13 at 09:34
  • Sorry working on windows platform. clock_gettime() is in linux. – Zax Dec 30 '13 at 09:37
  • Is your code taking a lot of time ? I mean, if you add printfs before and after the code, can you see them slowly or very fast ? – Josselin Poiret Dec 30 '13 at 09:41
  • I think you should then try calculating the time taken by the whole while loop instead of calculating the time for each iteration. You won't be able to get more precise times, even by doing some complex math. – Josselin Poiret Dec 30 '13 at 09:56