User Name
Password

Go Back   Planetarion Forums > Non Planetarion Discussions > Programming and Discussion
Register FAQ Members List Calendar Arcade Today's Posts

Reply
Thread Tools Display Modes
Unread 22 Dec 2002, 14:57   #1
Slidey
Registered User
 
Join Date: Mar 2001
Posts: 205
Slidey is an unknown quantity at this point
process timing

hola

im trying to time how long a program is running so as to get some sorta figures on bandwidth (data units per time period)

im using the following code: (condensed)

Code:
clock_t start, end;
struct tms t_start, t_end;

        start = times(&t_start);
then i call the function

i have a finishup function that is called when the program either gets an error or gets a SIGINT

Code:
void finishup(int exitval) {
        long tps = sysconf(_SC_CLK_TCK);
        end = times(&t_end);
        printf("elapsed: %6.2f secs\n", (float)(end - start)/tps);
        printf("caught ctrl-c, received %i packets, cleaning up\n", pktno);
        fclose(fout);
        fclose(procinfo);
        exit(exitval);
}
HOWEVER...!

the time it prints out is generally a lot less than the actual time it runs..

now i suspect its because im working on cpu time or thereabouts and not real time or IO time..

can anyone suggest a better way to do this (in C) as my books are at my birds

Slidey
__________________
#linux - home of idiots

#impulsed - home of genius..?
Slidey is offline   Reply With Quote
Unread 22 Dec 2002, 18:11   #2
Structural Integrity
Rawr rawr
 
Structural Integrity's Avatar
 
Join Date: Dec 2000
Location: Upside down
Posts: 5,300
Structural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriend
In Windows there are two timers one can use:
The system clock
The CPU clock

One of these two is pretty inaccurate and is sometimes not refreshed at regular intervals...

The accurate one is:
float timeGetTime(void);

And requires these files to be included/linked:
#include <mmsystem.h> //used for timing (LINKED WITH winmm.lib)
#pragma comment(lib, "winmm.lib")

I guess you're working under Linux (since I've never seen times() before) but I wouldn't be surprised if there were two clocks under Linux too.
Structural Integrity is offline   Reply With Quote
Unread 22 Dec 2002, 19:31   #3
Slidey
Registered User
 
Join Date: Mar 2001
Posts: 205
Slidey is an unknown quantity at this point
i dont use windows

i dont own a windows machine

anyone else ?
__________________
#linux - home of idiots

#impulsed - home of genius..?
Slidey is offline   Reply With Quote
Unread 22 Dec 2002, 21:32   #4
MT
/dev/zero
Retired Mod
 
MT's Avatar
 
Join Date: May 2000
Posts: 415
MT is an unknown quantity at this point
use gettimeofday()?
__________________
#linux : Home of Genius

<idimmu> ok i was chained to a desk with this oriental dude
MT is offline   Reply With Quote
Unread 12 Jan 2003, 13:14   #5
mikay
Registered User
 
Join Date: Aug 2000
Location: UK
Posts: 228
mikay is an unknown quantity at this point
time command?
__________________
<DrNick> hey i've been playing pa for ages and i know lots of people who bathe with 6 busty babes

<breeze|away> i agree about mang tho .. he is our mentor of perviness

R4: 48:25:13, 2E5 HC R5: n00b
R6: 3:10:1 Mangor, The Daddy
R7: 3:3:11 Retired
R8: c43 Finally free
PAX: 3:7:9 The Mentor of Perviness
mikay is offline   Reply With Quote
Reply



Forum Jump


All times are GMT +1. The time now is 22:20.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2002 - 2018