The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
Google UNIX.COM


High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Linux Going Big Time and Prime Time Against Windows, UNIX (WSJ) (Addict 3D) iBot UNIX and Linux RSS News 0 06-21-2007 01:10 PM
Start time/end time and status of crontab job thambi Shell Programming and Scripting 3 05-16-2007 07:24 AM
How To Provide Time Sync Using Nts-150 Time Server On Unix Network? pesty UNIX for Advanced & Expert Users 2 03-21-2007 11:20 PM
Losing Time/Time cloclk azdauk UNIX for Dummies Questions & Answers 4 11-06-2003 06:33 AM
default time in Solaris 8 for time-wait eloquent99 UNIX for Dummies Questions & Answers 1 04-01-2003 06:45 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #8  
Old 07-29-2002
flim flam flamma jamma
 

Join Date: May 2001
Location: Chicago IL, USA
Posts: 1,006
my brain is not working today. alas another monday couldnt go any faster.

do you know how i can get it to display 10th and 100ths of a second also?
Reply With Quote
Forum Sponsor
  #9  
Old 07-29-2002
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,616
Change
tm->tm_sec, tv.tv_usec);
to be
tm->sec, tv.tv_usec/100000);
or
tm->sec, tv.tv_usec/10000);
Reply With Quote
  #10  
Old 07-29-2002
flim flam flamma jamma
 

Join Date: May 2001
Location: Chicago IL, USA
Posts: 1,006
and even a basterd like myself must bow down to the awsome powers of Perderabo
Reply With Quote
  #11  
Old 07-30-2002
flim flam flamma jamma
 

Join Date: May 2001
Location: Chicago IL, USA
Posts: 1,006
well folks the following code is just a complete listing of the code Perderabo wrote.

This will print out the 10ths 100ths microseconds (1,000,0000th) of a second.

IE:
$./a.out
9 99 999999

Code:
#include <stdlib.h>
#include <sys/time.h>
main()
{
     struct timeval tv;
     struct timezone tz;
     struct tm *tm;
     gettimeofday(&tv, &tz);
     tm=localtime(&tv.tv_sec);
printf("%d %d %d \n", tv.tv_usec/100000, tv.tv_usec/10000, tv.tv_usec);
     exit(0);
}
This is for you people that get compiling errors reguarding the TM variable. On some OSes (AIX 4.3. && 4.3.3 in my case) tm is not defined in the header so you can add this snipit to the top of the sys/time.h headerfile and then compile. (DISCLAIMER NOR I OR UNIX.COM TAKE ANY RESPONSABILITY FOR ANY OF THE CODE SHOWN IN THIS POST)

Code:
/* I added this to make the microseconds program work needed to define TM */

 #include <sys/types.h>
 #ifdef HAVE_SYS_TIME_H
 #include <sys/time.h>

 +#if !defined(TM_IN_SYS_TIME)
 +#include <time.h>
 +#endif

 #else
 #include <time.h>
 #endif

 /* ENTER YOUR NAME HERE added this on ENTER THE CURRENT DATE HERE */
Reply With Quote
  #12  
Old 07-30-2002
auswipe's Avatar
Registered User
 

Join Date: Nov 2001
Location: Wide Awake Wylie, Texas
Posts: 536
Quote:
Originally posted by Optimus_P
and even a basterd like myself must bow down to the awsome powers of Perderabo
Duh!


__________________
Not quite as cool as all the other Kids...
Reply With Quote
  #13  
Old 11-21-2005
Registered User
 

Join Date: Nov 2005
Posts: 1
Unhappy Help Please

I don't understand. I need to measure how long it takes something to run in microseconds. Like this:


start

RUN CODE

end

display number of microseconds that it took to "RUN CODE"

Please help.
Reply With Quote
  #14  
Old 11-21-2005
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,616
Call gettimeofday() before and after the sequence in question. Then subtract the "before" value from the "after" value to get elapsed time. The only tricky part is that there are two integers (seconds and microseconds) to specify the time of day. So might need to "borrow" just like subtracting month and day to get days.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 06:30 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0