473,805 Members | 2,266 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2927
>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**********@n ews-int.gatech.edu> ,
Rajeev <gt*****@mail.g atech.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
2316
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" >> joe+="99999999999999999"
8
2691
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 consists of a bunch of components supplied by some application group. I got this to work, somewhat. The problem is that the application performs roughly (and this has not been measured, but a guess based on the rendering of the application GUI) 10x...
4
10362
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 that I am having is that sometimes the correct total shows up in print preview and sometimes it doesn't. Sometimes it is higher and sometimes it is lower (than the correct amount) and I cannot make any sense of the difference. The difference...
0
1016
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(); \* Body of Code *\
16
2611
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 gradual upgrade of my web programming skills from Classic ASP / VBS to ASP.NET / VB.NET. While the study of the language differences and all the new features in .NET has so far not been a traumatic experience, I am a bit shell-schocked after
9
7839
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 am in Visual Studio, running the program in debug mode, i want to bypass the password prompt because if i am the developer, i am definately allowed to use the program. I assumed that I could use the this.DesignMode property while in my main...
9
3274
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 problem occurs when i try to show a progress bar. The screen freezes. I know i'm not the first one to ask about it. but i'm looking
14
3451
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 program can save all running data to a file when I want it to stop, and can reload the data and continue to run from where it stops when the computer is free ?
7
2426
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 have had Mono running quite a bit faster than Vanilla .NET on my Windows XP installation, which has me wondering if I'm doing something that's sandbagging .NET. It's all console code, for Microsoft I'm just running the .exe file from the command...
0
9718
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9596
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10614
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10369
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9186
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7649
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5544
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5678
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3847
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.