LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices



Reply
 
Search this Thread
Old 03-31-2003, 02:34 AM   #1
Mad_C
Member
 
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,

Christian,
 
Old 03-31-2003, 12:35 PM   #2
revrendi
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, 02:12 AM   #3
Mad_C
Member
 
Registered: Dec 2002
Location: Austria
Distribution: Slax, ccux-Linux, coLinux
Posts: 49

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


Reply


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-28-2008 12:28 AM
find elapsed time innuendo_98 Programming 2 11-10-2005 09:03 AM
amarok progressbar time elapsed problem abattoir Linux - Software 0 04-13-2005 11:31 AM
elapsed time formula for open office calc philosophe Linux - Software 1 03-30-2005 06:32 AM
Howto Monitor elapsed time in a shell script rkrijger Linux - Software 2 03-11-2004 09:46 AM


All times are GMT -5. The time now is 06:50 AM.

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