process time (elapsed time) is always zero


Hello Everyone

I have one code for image compression alogrithm in c++. For my part, I have to measure execution time of different parts of algorithm. I am using clock() to measure time. But the probelm is that elapsed time is always zero. That is both begin time and end time are always same. While the calculation code between begin and end time is not small, it is transformation calculation. So there should be some elapse time for this part. I am postimg the part of the code that contains time measurement code because program is too big to post and explain.

********************************************
some class(){

double elapTime;
clock_t beginT, endT;

isFloat = type < 8 ? false : true;
if(isFloat) type -= 8;

beginT = clock();
status = FwdDWT(image, width, height, level, type);
endT = clock();

elapTime = ((double)(endT - beginT)*1000)/CLOCKS_PER_SEC;

//storin the result in *.txt file
ofstream resultFile ("test_results.txt", ios::out | ios::app);

resultFile << " Begin Time:" << beginT;
resultFile << " End Time:" << endT;
resultFile << " Elapsed Time:" << elapTime;
resultFile << " Clocks Per Sec:" << CLOCKS_PER_SEC << endl;
resultFile.close();
}

*******************************************

I am sure the code is correct because it records begin and end time in test_results file. But why these both values are always same? Can anyone help me with this problem?
Dear God, what is that?

clock() return the number of ticks since the beginning of the program. endT-beginT is the number of clocks between the two calls to clock(), so I can't imagine what you were thinking when you wrote that expression.

You can get the time in seconds with float(clock())/float(CLOCKS_PER_SEC).

Hey Helios

I don't have any previous experience with c++. I have taken help from web about clock(). Please Can you tell me which expression are you talking about from my part ?
elapTime = ((double)(endT - beginT)*1000)/CLOCKS_PER_SEC;

Helios,

You mean that I should change:

beginT = clock(); to beginT = float(clock())/float(CLOCKS_PER_SEC);

so that I get seconds in beginT. And same for endT.

Then elapTime = endT - beginT;

Am I right? Please correct me if I am wrong. It looks like that I have misunderstood clock() concept.
Right.

Helios,

Well, I tried what you said me to do. Still I get zero elapset time. beginT and endT are both same always. So I am back to same problem.
Last edited on
And you're sure that the call to FwdDWT() takes more than 1 ms?

That I doubt. I assume that it should take atleast 1 ms to do complex wavelet transformation on 256 * 256 image. Is there any otherway that I can measure time in resolution smaller than 1ms or in ns?
No. The smallest resolution supported by the system is 1/CLOCKS_PER_SEC seconds.

If the code looks like this (names changed for simplicity):
1
2
3
4
t0=clock();
//code you want to benchmark
t1=clock();
elapsed=t1-t0;
then elapsed contains the exact time the code took in CLOCKS_PER_SECths of a second.
Last edited on
Topic archived. No new replies allowed.