1

Topic: How to learn runtime of any function?

There is some function myfunc - for example, void myfunc ();. How to learn time of its performance? What functions should be caused before function myfunc and what - after function invocation myfunc, to learn current time for these two execution points of the program? How to receive a difference between these two times?

2

Re: How to learn runtime of any function?

Hello, RussianFellow, you wrote: RF> There is some function myfunc - for example, void myfunc ();. RF> How to learn time of its performance? RF> what functions should be caused before function myfunc and what - after function invocation myfunc, to learn current time for these two execution points of the program? How to receive a difference between these two times? GetTickCount or to read about performance counters for Windows

3

Re: How to learn runtime of any function?

Hello, RussianFellow, you wrote: RF> There is some function myfunc - for example, void myfunc ();. RF> How to learn time of its performance? LARGE_INTEGER StartingTime, EndingTime, ElapsedMicroseconds; LARGE_INTEGER Frequency; QueryPerformanceFrequency (&Frequency); QueryPerformanceCounter (&StartingTime);//Activity to be timed void myfunc (); QueryPerformanceCounter (&EndingTime); ElapsedMicroseconds. QuadPart = EndingTime. QuadPart - StartingTime. QuadPart;////We now have the elapsed number of ticks, along with the//number of ticks-per-second. We use these values//to convert to the number of elapsed microseconds.//To guard against loss-of-precision, we convert//to microseconds *before* dividing by ticks-per-second.//ElapsedMicroseconds. QuadPart * = 1000000; ElapsedMicroseconds. QuadPart / = Frequency. QuadPart; Runtime myfunc () is in microseconds in ElapsedMicroseconds. QuadPart

4

Re: How to learn runtime of any function?

And function clock () does not approach? unsigned int time1 = clock (); myfunc (); unsigned int time2 = clock (); double diff = (double) (time2-time1) / (double) CLOCKS_PER_SEC;

5

Re: How to learn runtime of any function?

Hello, RussianFellow, you wrote: RF> There is some function myfunc - for example, void myfunc ();. RF> How to learn time of its performance? To call her in a cycle one million times, to learn time before and after a cycle, to calculate a difference, to divide into one million. RF> what functions should be caused before function myfunc and what - after function invocation myfunc, to learn current time for these two execution points of the program? How to receive a difference between these two times? Functions which return time, are fulfilled any time. If you are going to measure time of a single call errors because of it will be too great. I, naturally assume that your function is fulfilled rather quickly. And so, under  use QueryPerformanceCounter (). And to learn, with what speed it ticks, at first call QueryPerformanceFrequency ()

6

Re: How to learn runtime of any function?

Hello, RussianFellow, you wrote: RF> And function clock () does not approach? And you know, to that is equal CLOCKS_PER_SEC? More precisely, than 1 / CLOCKS_PER_SEC, you function clock () nothing .