471,122 Members | 1,168 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,122 software developers and data experts.

Is there a timer function in C++ ?

Hi

I have written some code but I want to know how long it takes to run the programme. I was wondering if there is a function similar to the tic toc function in matlab that I could embed within my code.

Your suggestions would be extremely appreciated.

Thanks
Dec 13 '06 #1
4 15130
horace1
1,510 Expert 1GB
Hi

I have written some code but I want to know how long it takes to run the programme. I was wondering if there is a function similar to the tic toc function in matlab that I could embed within my code.

Your suggestions would be extremely appreciated.

Thanks
if you are working a Unix environment you can use the time command to run a program and get the elapsed time, cpu time, etc. see
http://www.mcsr.olemiss.edu/cgi-bin/man-cgi?time
Dec 13 '06 #2
if you are working a Unix environment you can use the time command to run a program and get the elapsed time, cpu time, etc. see
http://www.mcsr.olemiss.edu/cgi-bin/man-cgi?time
Thanks for your help but i wont be working in a Unix environment, I am running my code in windows.

Is there a different method that I could use?

Thanks
Dec 13 '06 #3
horace1
1,510 Expert 1GB
Thanks for your help but i wont be working in a Unix environment, I am running my code in windows.

Is there a different method that I could use?

Thanks
you can use function clock() in <time.h> to measure the elapsed time since program startup, e.g. to measure elapsed time for a section of code
Expand|Select|Wrap|Line Numbers
  1.     time_t  start_time = clock();                              /*  get start time  */
  2. ........ code to measure
  3.     float time1 = (float) (clock() - start_time) / CLOCKS_PER_SEC; 
  4.     printf("time for code was %f seconds\n", time1);
  5.  
the actual CPU time could well be different depending upon the number of processes running, etc
Dec 13 '06 #4
If u have VC++, u can use profile.exe. Visit Microsoft website for help and more info.
Dec 21 '06 #5

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

4 posts views Thread by Christine | last post: by
6 posts views Thread by Antti Laakso | last post: by
1 post views Thread by jmgro | last post: by
7 posts views Thread by genesistr | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.