473,382 Members | 1,705 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 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 15386
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

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

Similar topics

4
by: Christine | last post by:
I've implemented a countdown timer for a tutorial web page that should give the user 45 minutes to complete the test, only to find that the timer is slowly 'losing' time. On average, it actually...
7
by: J. Hill | last post by:
I have a Windows Service with a timer but the .Tick event is not being fired/called. Don't know what code to include...I enabled and started the timer...I have the exact same code in a Windows...
6
by: Antti Laakso | last post by:
Hi i have function like above Public Sub halytystutkinta() Dim ds As New DataSet ds = dl2.HaeHalytys() Dim onkohal As Int16 onkohal = ds.Tables(0).Rows(0).Item("onkohalytys") halid =...
7
by: Noozer | last post by:
I have a timer on a form. It isn't firing at all. I know that the timer is enabled, and that the interval is low (4000, which should be 4 seconds). To ensure the timer wasn't being inadvertantly...
1
by: jmgro | last post by:
I have spent way too much time trying to solve the following problem: I have a datalist with a timer in the footer template. It works wonderfully except when the user pages back, then forward,...
10
by: Ryan | last post by:
I'm creating a website that monitors the status of servers using My.Computer.Network.Ping. I'm looking for a way to fire off my Ping() function every second or so. I see a Timer control...
4
by: grayaii | last post by:
Hi, I have a simple form that handles all its paint functionality like so: this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.Opaque, true); And the entry point to this...
4
by: jwriteclub | last post by:
Hello all, I have a quick question about timers in C#. I have a System.Windows.Forms.Timer timer (the kind you "drag" out of the toolbox. It looks something like this: public class...
7
by: ssecorp | last post by:
I am not clear about the results here. from timeit import Timer import Decorators def fib(n): a, b = 1, 0 while n: a, b, n = b, a+b, n-1
7
by: genesistr | last post by:
Hi, I have timer class and some classes use timer. but when i come back from timer with callback function, i can see this. properties. function Timer(dName, dCallback){ this.timer = null;...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.