Getting time in millisecond resolution 
Author Message
 Getting time in millisecond resolution

Is there ANSI-C way to get system time in format hh.mm.ss.sss (.sss represent
milliseconds). Structure time_t doesn't seem to include elements for
millisecond part. There seems to be some OS/Compiler depended ways for this
(like Borland's dos.h), but how to do it in ANSI-C? Do I have to use clock()
function also? Of course, the accuracy may not be 1 ms, but even 55ms would be
enough.

--
  Timo Sakari

  WWW: http://www.*-*-*.com/
  To reply, remove text "spammi.imee." from my e-mail address.



Thu, 12 Jul 2001 03:00:00 GMT  
 Getting time in millisecond resolution

Quote:

>Is there ANSI-C way to get system time in format hh.mm.ss.sss (.sss represent
>milliseconds).

No, the most common way is with gettimeofday(),
Tim Prince



Thu, 12 Jul 2001 03:00:00 GMT  
 Getting time in millisecond resolution

Quote:

> Is there ANSI-C way to get system time in format hh.mm.ss.sss (.sss represent
> milliseconds). Structure time_t doesn't seem to include elements for
> millisecond part. There seems to be some OS/Compiler depended ways for this
> (like Borland's dos.h), but how to do it in ANSI-C? Do I have to use clock()
> function also? Of course, the accuracy may not be 1 ms, but even 55ms would be
> enough.

> --
>   Timo Sakari

>   WWW: http://personal.inet.fi/koti/timo.sakari/
>   To reply, remove text "spammi.imee." from my e-mail address.

Use the select() function in a creative way.
.

--
David Pace  Free Trading software: http://www.daveware.com



Thu, 12 Jul 2001 03:00:00 GMT  
 Getting time in millisecond resolution

Quote:


> >Is there ANSI-C way to get system time in format hh.mm.ss.sss (.sss represent
> >milliseconds).

> No, the most common way is with gettimeofday(),
> Tim Prince


   gettimeofday() could go like this......

  #include <sys/time.h>

  //time scale 1000000 = 1 sec
  //fixed point with 6 decimals

  typedef long long int UTime_t;

UTime_t utime(void)
 {
    struct timeval tv;
    struct timezone tz;
    gettimeofday(&tv, &tz);
    return (UTime_t)tv.tv_sec * 1000000 + (UTime_t)tv.tv_usec;
 }

void uwait(UTime_t usecs)
 {
    struct timeval tv;
    tv.tv_sec = usecs/1000000;
    tv.tv_usec = usecs-(UTime_t)tv.tv_sec*1000000;
    select(0, 0, 0, 0, &tv);
 }



Thu, 12 Jul 2001 03:00:00 GMT  
 Getting time in millisecond resolution


Quote:

> > Is there ANSI-C way to get system time in format hh.mm.ss.sss (.sss represent
> > milliseconds). Structure time_t doesn't seem to include elements for
> > millisecond part. There seems to be some OS/Compiler depended ways for this
> > (like Borland's dos.h), but how to do it in ANSI-C? Do I have to use clock()
> > function also? Of course, the accuracy may not be 1 ms, but even 55ms would be
> > enough.

> > --
> >   Timo Sakari

> >   WWW: http://personal.inet.fi/koti/timo.sakari/
> >   To reply, remove text "spammi.imee." from my e-mail address.

> Use the select() function in a creative way.
> .

<Jack>

Since select() is not ANSI, how does this answer the question?

</Jack>
--
Do not email me with questions about programming.
Post them to the appropriate newsgroup.
Followups to my posts are welcome.



Thu, 12 Jul 2001 03:00:00 GMT  
 Getting time in millisecond resolution
N8TM schrieb:

Quote:


> >Is there ANSI-C way to get system time in format hh.mm.ss.sss (.sss represent
> >milliseconds).

> No, the most common way is with gettimeofday(),

In would not call a proprietory and unportable function called
"gettimeofday()" very common. The most common way to *likely*
get a subsecond resolution is the ANSI-C "clock()" function.
The actual resolution is system specific. You should be able to
find it in your compiler manuals. It will typically be as fine a
resolution as the system can support.

This value is quite different from getting wall clock time, though.
But what I like about "clock()" is, that it has a portable prototype
and you only have to find out if the current compiler supports a
resolution that's fine enough.

Stephan
(initiator of the campaign against grumpiness in c.l.c)



Fri, 13 Jul 2001 03:00:00 GMT  
 Getting time in millisecond resolution


Quote:
>N8TM schrieb:


>> >Is there ANSI-C way to get system time in format hh.mm.ss.sss (.sss represent>> >milliseconds).

>> No, the most common way is with gettimeofday(),

>In would not call a proprietory and unportable function called
>"gettimeofday()" very common.

Perhaps not, but that still doesn't rule out it being the "most common". :-)
However the "most common" in at least some senses is probably a Windows API
function.

Quote:
>The most common way to *likely*
>get a subsecond resolution is the ANSI-C "clock()" function.
>The actual resolution is system specific. You should be able to
>find it in your compiler manuals. It will typically be as fine a
>resolution as the system can support.

However the value that clock() returns isn't defined to have anything to
do with the "system time" so isn't a valid answer to the question.

Quote:
>This value is quite different from getting wall clock time, though.
>But what I like about "clock()" is, that it has a portable prototype
>and you only have to find out if the current compiler supports a
>resolution that's fine enough.

If it doesn't give you the system time it isn't much help here no matter
how "portable" the prototype is. :-)

--
-----------------------------------------


-----------------------------------------



Fri, 13 Jul 2001 03:00:00 GMT  
 Getting time in millisecond resolution


Quote:

>> Is there ANSI-C way to get system time in format hh.mm.ss.sss (.sss represent
>> milliseconds). Structure time_t doesn't seem to include elements for
>> millisecond part. There seems to be some OS/Compiler depended ways for this
>> (like Borland's dos.h), but how to do it in ANSI-C? Do I have to use clock()
>> function also? Of course, the accuracy may not be 1 ms, but even 55ms would be>> enough.

>> --
>>   Timo Sakari

>>   WWW: http://personal.inet.fi/koti/timo.sakari/
>>   To reply, remove text "spammi.imee." from my e-mail address.

>Use the select() function in a creative way.

There is no select() function in ANSI-C. Also on platforms I've seen that
do have such a function it has nothing to do with system time (any more
than clock() does in my previous response).

--
-----------------------------------------


-----------------------------------------



Fri, 13 Jul 2001 03:00:00 GMT  
 Getting time in millisecond resolution

Quote:


> > Is there ANSI-C way to get system time in format hh.mm.ss.sss (.sss represent
> > milliseconds). Structure time_t doesn't seem to include elements for
> > millisecond part. There seems to be some OS/Compiler depended ways for this
> > (like Borland's dos.h), but how to do it in ANSI-C? Do I have to use clock()
> > function also? Of course, the accuracy may not be 1 ms, but even 55ms would be
> > enough.

> > --
> >   Timo Sakari

> >   WWW: http://www.*-*-*.com/
> >   To reply, remove text "spammi.imee." from my e-mail address.

> Use the select() function in a creative way.

Yeah - this being c.l.c you'll have to be creative and define it too.
It's not a standard function...

--
 { Sunil Rao }
    "From life's dawn it is drawn down,
 Abel is Cain's brother and {*filter*}s they have sucked the same."
   -  HOPKINS, Gerard Manley, in "The Wreck of the Deutschland".



Fri, 13 Jul 2001 03:00:00 GMT  
 Getting time in millisecond resolution

Quote:

>what I like about "clock()" is, that it has a portable prototype
>and you only have to find out if the current compiler supports a
>resolution that's fine enough.

clock() solves a different problem and is quite likely to require replacement
by something which works, unless you confine yourself to a certain class of
systems.  Of course, clock() should be used, if it addresses the requirement.
Tim Prince



Sat, 14 Jul 2001 03:00:00 GMT  
 
 [ 10 post ] 

 Relevant Pages 

1. Storing date/time value on SQL server with milliseconds resolution using vc++ and ado 2.0

2. help getting time in milliseconds

3. Getting current system time in milliseconds

4. CTime and Millisecond Resolution

5. Minimum Wait Time (System Time Resolution)

6. sleeping for time under the millisecond

7. How to convert local time to milliseconds?

8. Time delay in milliseconds

9. last time a file was modified in milliseconds

10. time in milliseconds

11. Millisecond Timing

12. Elapsed time in milliseconds in C, please help!

 

 
Powered by phpBB® Forum Software