473,835 Members | 1,871 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

measuring running time

Hi,

I'm trying to find a decent way to measure program running time.
I know clock() is probably the standard way of doing it but clock_t
overflows too quickly.
The target program running time ranges from a few seconds to a day.

Is there a decent+portable way to deal with this?

Thank you.

Apr 26 '07 #1
2 4647
In article <11************ **********@r35g 2000prh.googleg roups.com>,
upperclass <th********@gma il.comwrote:
>Hi,

I'm trying to find a decent way to measure program running time.
I know clock() is probably the standard way of doing it but clock_t
overflows too quickly.
The target program running time ranges from a few seconds to a day.
Is there a decent+portable way to deal with this?
If wall-clock time is a close enough approximation, you can use time_t,
time(), and difftime().

If you need running time but you can arrange to call clock() often enough
to catch it between wraparounds, that may work. (You can at least detect
wraparound and tell how often it's happened; I don't know off the top of
my head whether there's a way to tell how much time a single wraparound
cycle represents. If clock_t is required to be an unsigned type, then
it should be ((clock_t)-1)/CLOCKS_PER_SEC seconds.)

If you need actual running time and catching clock_t wraparounds
doesn't qualify as a "decent" way to deal with it, then there's no
decent and portable way.

(There are fairly easy ways to get the information from outside the
program on most OSs most people are likely to encounter. If you're on
a unix-like system[1], you can use time to get wall-clock and actual
running time reported when it finishes, or you can use ps or top to look
up running time while the program is running; under Windows, you can
get the total CPU time a running process has used from the task manager.
If you're using system tools to get times for running processes, you'll
probably want to add something like
--------
puts("Done; if you want to check the total running time, do it now.");
puts("Press Enter to continue");
getchar();
--------
to the bottom of main() just before it returns.)
dave

[1] I don't have a Mac to try it on, but I strongly suspect that MacOS is
sufficiently unix-like for this to work. Any BSD, Linux, or UNIX(TM)
derivative certainly will be.

--
Dave Vandervies dj******@csclub .uwaterloo.ca
I don't know what happens when you buy a car, but it must
be DEBILITATING. CRIPPLING.
--Maarten Wiltink in the scary devil monastery
Apr 26 '07 #2
upperclass <th********@gma il.comwrites:
I'm trying to find a decent way to measure program running time.
I know clock() is probably the standard way of doing it but clock_t
overflows too quickly.
The target program running time ranges from a few seconds to a day.

Is there a decent+portable way to deal with this?
You could check the return value of clock() from time to time
while the program runs and keep a running total.
--
"When in doubt, treat ``feature'' as a pejorative.
(Think of a hundred-bladed Swiss army knife.)"
--Kernighan and Plauger, _Software Tools_
Apr 26 '07 #3

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

Similar topics

3
2319
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"
5
5452
by: chellappa | last post by:
hi, i want to find the ruuning time of program using c .. problem: i want to find the running time of program using c , i have one routine in c,,, i want to find how much , its take for running.. usinf time_t is tell only seconds in basee of system clock .. i need internally excact running time of program... send me small examples or ideas by
3
9308
by: SSG | last post by:
Hi All! I know how to calculate the running time of a particular routine, but i want to know how to reduce the running time in a program........... can anyone knows help me........ also tell me the definitions for system time, user time, real time..........
4
2929
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 *\
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 *\
6
2937
by: Grace | last post by:
Hello, I write a Web Application: its UI has a DataGrid controller. The web application gets huge data from SQL Server, then shows the result after processing these data. It needs much time to run it. But, it happened an error after running less than 60 seconds. This error didn't explain detail. I set
20
1991
by: upperclass | last post by:
Hi, I'm trying to find a decent way of measuring the running time of a long-running program. Say, the running time ranges from several seconds to more than a day. The standard clock() function seems inadequate for this task. (I read somewhere in this group that clock_t would likely overflow after <1 hour).
0
9810
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
10524
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10562
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
10236
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9348
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...
0
6968
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5805
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3997
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3092
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.