473,545 Members | 2,081 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 4636
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
2302
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
5440
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...
3
9292
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
2911
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
1009
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
2927
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
1956
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
7468
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...
0
7808
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...
0
7757
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...
0
5972
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...
1
5329
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...
0
3450
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...
0
3443
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1884
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
704
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...

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.