Connecting Tech Pros Worldwide Forums | Help | Site Map

time the code

Member
 
Join Date: May 2007
Posts: 35
#1: Jun 3 '08
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.  
  11.  
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
Expert
 
Join Date: Mar 2007
Location: Chennai
Posts: 1,258
#2: Jun 3 '08

re: time the code


Quote:

Originally Posted by eternalLearner

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.  
  11.  
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
Newbie
 
Join Date: Jun 2008
Posts: 6
#3: Jun 28 '08

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
Member
 
Join Date: May 2007
Posts: 35
#4: Jul 4 '08

re: time the code


Quote:

Originally Posted by gpraghuram

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.
Member
 
Join Date: May 2007
Posts: 35
#5: Jul 4 '08

re: time the code


Quote:

Originally Posted by varnie

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