472,325 Members | 1,583 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,325 software developers and data experts.

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 4539
In article <11**********************@r35g2000prh.googlegroups .com>,
upperclass <th********@gmail.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********@gmail.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
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...
5
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...
3
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...
4
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>...
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>...
6
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...
20
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...
0
by: tammygombez | last post by:
Hey fellow JavaFX developers, I'm currently working on a project that involves using a ComboBox in JavaFX, and I've run into a bit of an issue....
0
by: tammygombez | last post by:
Hey everyone! I've been researching gaming laptops lately, and I must say, they can get pretty expensive. However, I've come across some great...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: CD Tom | last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...

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.