954,499 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Measuring execution time of a loop

Hello!

I have coded a compression technique and I am having trouble in measuring the speed of it. I tried to generate log of start time and end time, but compression time of same file varies a lot under windows. That may be happening because other processes would be consuming resources my program could me in blocked mode for a while. Can anyone please suggest me a way to measure the execution time of my program minus the waiting time when it was blocked?

I can think of three possible ways

(1) Setup a minimal Linux and run my program there so that no other process would interfere my program.

(2) Use some tool that would help me generate the report about the execution of my program.

(3) Code my program in such a way that it would tell me the absolute execution time at the end of compression.

Please guide me...

theprofoundgeek
Newbie Poster
8 posts since Oct 2009
Reputation Points: 10
Solved Threads: 0
 

If you use the clock() function, it will return the clock ticks elapsed by your process only. My guess is that you have been using a general local-time function like "time()" to measure your elapsed times. The time() function and the clock() function are fundamentally different in the sense that clock() return the number of clock-ticks since the start of the calling process and only the clock-ticks consumed by the calling process are counted. In other words, if you use the clock function, there should be no variability introduced by having other processes running on the computer.

N.B. When measuring performance of algorithms that do file I/O, always expect variability just from the fact that file I/O is usually the main bottleneck operation and it is not very steady.

mike_2000_17
Posting Virtuoso
Moderator
2,136 posts since Jul 2010
Reputation Points: 1,634
Solved Threads: 457
 

Hey Mike!

Thanks for the guidance! It made perfect sense...

http://www.gnu.org/s/hello/manual/libc/Processor-And-CPU-Time.html#Processor-And-CPU-Time

Now the secondary problem is of IO time variation... as the read speed from HDD may vary a lot.

Possible solution : Test under a linux after copying the file to be compressed and linux in RAM... like knoppix does. So this should remove the variation.

Do you agree this would work?

theprofoundgeek
Newbie Poster
8 posts since Oct 2009
Reputation Points: 10
Solved Threads: 0
 

>> Do you agree this would work?

It would certainly help. It wouldn't completely solve the problem, RAM is also variable in access time, but certainly not as much as the HD.

Anyways, what is wrong with variability? What is wrong with taking statistics on the performance of your algorithm? You run it multiple times and take the average running time as the performance value you are looking for. What's wrong with that?

mike_2000_17
Posting Virtuoso
Moderator
2,136 posts since Jul 2010
Reputation Points: 1,634
Solved Threads: 457
 

@theprofoundgeek (thread starter)
I am having similar issue on windows vista. Not able to calculate the time my program took to complete.
Would you please paste your code(only related to time calculation) here, in case you solved the issue?

ExpertsGuide
Newbie Poster
6 posts since Nov 2011
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: