473,387 Members | 1,520 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,387 software developers and data experts.

Running time of a code

I want to calculate the running time of my program, which runs for a
long time(~ a day). This is what I am doing in my code:
#include <time.h>
clock_t tend, tstart;
tstart = clock();

\* Body of Code *\

tend = clock();
Running Time = ((double) (tend - tstart) / (double) CLOCKS_PER_SEC));

But for my codes which run for a long time, I am not getting the right
value for the running time variable. Please help me out!!

Thanks
Rajeev.
Nov 15 '05 #1
4 2901
>I want to calculate the running time of my program, which runs for a
long time(~ a day).
clock() measures CPU time, which is a lot like football or basketball
game clock time: it doesn't run all the time.
#include <time.h>
clock_t tend, tstart;
tstart = clock();

\* Body of Code *\ ^^ this is a syntax error
tend = clock();
Running Time = ((double) (tend - tstart) / (double) CLOCKS_PER_SEC)); ^ extra )

Check out the data type of clock_t and the value of CLOCKS_PER_SEC.
If, for example, clock_t is 32 bits signed and CLOCKS_PER_SEC is
1,000,000 then clock_t overflows at about 0.6 hours.
But for my codes which run for a long time, I am not getting the right
value for the running time variable. Please help me out!!


How do you know it's wrong? If it's negative, it probably overflowed.
If it's just too low, well, a program sitting at an input prompt
for a few decades might well accumulate only a few milliseconds of
CPU time, if that much. Or it might have overflowed.

The only solution I know of to overflow is to take samples more often
(yes, this can be a pain), convert to better units in a floating-point
variable, and add up the results.

Gordon L. Burditt
Nov 15 '05 #2
In article <dc**********@news-int.gatech.edu>,
Rajeev <gt*****@mail.gatech.edu> wrote:
I want to calculate the running time of my program, which runs for a
long time(~ a day). This is what I am doing in my code:
#include <time.h>
clock_t tend, tstart;
tstart = clock();

\* Body of Code *\

tend = clock();
Running Time = ((double) (tend - tstart) / (double) CLOCKS_PER_SEC));

But for my codes which run for a long time, I am not getting the right
value for the running time variable. Please help me out!!


Check the values of CLOCKS_PER_SEC and the type of clock_t in your
implementation. Is your implementation capable of handling times that
are a day apart? For example, if clock_t is a 32 bit integer, and
CLOCKS_PER_SEC = 1000000, then this will not work.
Nov 15 '05 #3
Rajeev wrote:
I want to calculate the running time of my program, which runs for a
long time(~ a day). This is what I am doing in my code:
#include <time.h>
clock_t tend, tstart;
tstart = clock();

\* Body of Code *\

tend = clock();
Running Time = ((double) (tend - tstart) / (double) CLOCKS_PER_SEC));

But for my codes which run for a long time, I am not getting the right
value for the running time variable. Please help me out!!


You can probably use a shell command instead (e.g. `time' under GNU/Linux).

August
Nov 15 '05 #4


akarl wrote:
Rajeev wrote:
I want to calculate the running time of my program, which runs for a
long time(~ a day). This is what I am doing in my code:
#include <time.h>
clock_t tend, tstart;
tstart = clock();

\* Body of Code *\

tend = clock();
Running Time = ((double) (tend - tstart) / (double) CLOCKS_PER_SEC));

But for my codes which run for a long time, I am not getting the right
value for the running time variable. Please help me out!!


You can probably use a shell command instead (e.g. `time' under GNU/Linux).

August

Gprof on Linux is also better.I think probably overflow occurred.

Nov 15 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Edg Bamyasi | last post by:
This Is A Late Cross Post from comp.lang.python. It seems the mistery is deeper then i expected. What is the running time of conactination on character strings. i.e. >> joe="123" >>...
8
by: nickdu | last post by:
I'm trying to isolate "applications" into their own application domain within a single process. I've quoted applications because it's a logical representation of an application. Basically it...
4
by: Bill Dika | last post by:
Hi I am trying to calculate a running total of a calculated textbox (tbAtStandard) in GroupFooter1 for placement in a textbox (tbTotalAtStandard) on my report in Groupfooter0. The problem...
0
by: Rajeev | last post by:
I want to calculate the running time of my program, which runs for a long time(~ a day). This is what I am doing in my code: #include <time.h> clock_t tend, tstart; tstart = clock(); \*...
16
by: TB | last post by:
Hi all: If you think that the following comments are absolute amateurish, then please bear with me, or simply skip this thread. A couple of months back I made the decision to initiate a...
9
by: Michael.Suarez | last post by:
Suppose I have a program that prompts you with a dialogbox to enter a password. If you get the password correct, it allows you into the program, else it kills the program. Suppose that when I...
9
by: esakal | last post by:
Hello, I'm programming an application based on CAB infrastructure in the client side (c# .net 2005) Since my application must be sequencally, i wrote all the code in the UI thread. my...
14
by: fdu.xiaojf | last post by:
Hi, I have a program which will continue to run for several days. When it is running, I can't do anything except waiting because it takes over most of the CUP time. Is it possible that the...
7
by: Wisgary | last post by:
I'm doing some benchmarking tests to compare Microsoft's CLR against Mono's CLR. I could use some suggestions for how to objectively compare the code. To my surprise the few tests I've run so far...
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
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.