Go Job Hunting at the LQ Job Marketplace
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 03-31-2003, 01:34 AM   #1
Registered: Dec 2002
Location: Austria
Distribution: Slax, ccux-Linux, coLinux
Posts: 49

Rep: Reputation: 15
Question 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,

Old 03-31-2003, 11:35 AM   #2
LQ Newbie
Registered: Mar 2003
Location: California, USA
Distribution: Linux from Scratch
Posts: 9

Rep: Reputation: 0
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
Old 04-01-2003, 01:12 AM   #3
Registered: Dec 2002
Location: Austria
Distribution: Slax, ccux-Linux, coLinux
Posts: 49

Original Poster
Rep: Reputation: 15
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!


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash: how to get time (in seconds) elapsed since creation of a file? J_Szucs Linux - General 6 12-27-2008 11:28 PM
find elapsed time innuendo_98 Programming 2 11-10-2005 08:03 AM
amarok progressbar time elapsed problem abattoir Linux - Software 0 04-13-2005 10:31 AM
elapsed time formula for open office calc philosophe Linux - Software 1 03-30-2005 05:32 AM
Howto Monitor elapsed time in a shell script rkrijger Linux - Software 2 03-11-2004 08:46 AM

All times are GMT -5. The time now is 05:25 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration