LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   getting elapsed time.. (https://www.linuxquestions.org/questions/programming-9/getting-elapsed-time-52625/)

Mad_C 03-31-2003 02:34 AM

getting elapsed time..
 
I am trying to time TCP/IP transfers between two boxes. I'd love to be able to take a look at how the ttcp included with Suse8.1 is programmed, but can't find the sources anywhere.

So, I just took one of the echoserver/echoclient examples floating around (from Paul Griffiths, to be exact) and adapted it.

The transfer part works fine using send and recv, but I can't time the stuff! Tried to use times(), which is said to return the elapsed ticks since boottime, but I always get 0 back!
sysconf(_SC_CLK_TCK) returns 100 ticks/sec, btw.

Can somebody please tell me what I'm doin' wrong, or, even better, tell me how to measure with (sub)millisecond resolution?

Thanks in advance,

Christian, :newbie:

revrendi 03-31-2003 12:35 PM

If you run the following do you get 0 for the times?

---- 8< --- SOURCE

#include <stdio.h>
#include <sys/times.h>
#include <unistd.h>

int main( void )
{
clock_t beginticks;
clock_t endticks;

beginticks = times( NULL );
printf( "begin ticks %lu\n", beginticks );

sleep( 2 );

endticks = times( NULL );
printf( "end ticks %lu\n", endticks );

printf( "elapsed ticks %lu\n", endticks - beginticks );

return 0;
}

---- 8< --- SOURCE

If so it sounds like you might have something decently severe (and probably esoteric) going on. Like a mismatch between header files and installed standard c library. That can be a real pain to diagnose correctly. -- Rev

Mad_C 04-01-2003 02:12 AM

revrendi
sometimes I surprise even myself with my stupidity: I should have known that, on a fast machine, I need to convert the result of times() to double BEFORE I divide by tickspersecond %>(
So, no esoteric things going on, the machine was right, the human blundered..
Thanks anyway for trying to help!
Christian


All times are GMT -5. The time now is 12:17 PM.