Sign In | Register Now About Bytes | Help | Site Map
Connecting Tech Pros Worldwide

time the code

Question posted by: eternalLearner (Newbie) on June 3rd, 2008 05:35 AM
hi ,
i need to calculate the actual running time of my code .
that is i don't want the time wen my application is swapped out of the memory to show up in the time of the program,which actually happens wen i use the following :
Expand|Select|Wrap|Line Numbers
  1. time_t initialtime;
  2. time_t finaltime;
  3. (void)time(&initialtime);
  4.  
  5. //do something 
  6.  
  7. (void)time(&finaltime);//end of the time
  8.  
  9. int time_taken  = finaltime - initialtime;
  10.  


please let me know if there is any other way to time the program,so the constraint i have specified is taken care of.
thanks in advance.
gpraghuram's Avatar
gpraghuram
Expert
1,118 Posts
June 3rd, 2008
09:32 AM
#2

Re: time the code
Quote:
hi ,
i need to calculate the actual running time of my code .
that is i don't want the time wen my application is swapped out of the memory to show up in the time of the program,which actually happens wen i use the following :
Expand|Select|Wrap|Line Numbers
  1. time_t initialtime;
  2. time_t finaltime;
  3. (void)time(&initialtime);
  4.  
  5. //do something 
  6.  
  7. (void)time(&finaltime);//end of the time
  8.  
  9. int time_taken  = finaltime - initialtime;
  10.  


please let me know if there is any other way to time the program,so the constraint i have specified is taken care of.
thanks in advance.



Try using time <your executable> from command promt if u are running this in Unix.
I hope this will give the required info

raghu

Reply
varnie's Avatar
varnie
Newbie
6 Posts
June 28th, 2008
10:36 PM
#3

Re: time the code
you can use, for example, Boost Timer Library. more info here:
http://www.boost.org/doc/libs/1_35_0/libs/timer/timer.htm

Reply
eternalLearner's Avatar
eternalLearner
Newbie
21 Posts
July 4th, 2008
12:43 PM
#4

Re: time the code
Quote:
Try using time <your executable> from command promt if u are running this in Unix.
I hope this will give the required info

raghu


thanks,i will try it.

Reply
eternalLearner's Avatar
eternalLearner
Newbie
21 Posts
July 4th, 2008
12:44 PM
#5

Re: time the code
Quote:
you can use, for example, Boost Timer Library. more info here:
http://www.boost.org/doc/libs/1_35_0/libs/timer/timer.htm


thanks for the info :)

Reply
Reply
Not the answer you were looking for? Post your question . . .
189,321 Experts ready to help you find a solution.
Sign up for a free account, or Login (if you're already a member).

Latest Articles: Read & Comment
Top C / C++ Forum Contributors