Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Re: timestamp in milliseconds

by gryphon (Abbot)
on Jul 12, 2005 at 15:19 UTC ( #474294=note: print w/replies, xml ) Need Help??

in reply to timestamp in milliseconds

Greetings mosh,

Check out Time::HiRes.

use Time::HiRes qw(time); print time;

gryphon Development Manager (DSMS)
code('Perl') || die;

Replies are listed 'Best First'.
Re^2: timestamp in milliseconds
by bart (Canon) on Jul 13, 2005 at 07:39 UTC
    Caution: Time::HiRes returns a floating point number, but its precision is not necessarily very fine. For example, I noticed that on Windows, Time::HiRes::time() works in steps of around 55ms, or 1/18 of a second. That's the frequency of the system timer interrupt.

      I've also seen (and commented on) this, but it only happens under special circumstances.

      Under normal circumstances, with reasonably up-to-date versions of Perl and Time::HiRes and an NT-based version of Windows, you should be getting much better than 1/18 second resolution. On my machine it's in the order of 60 microseconds (1/16666th of a second):

      P:\test>perl -MTime::HiRes=time -wle"print time for 1 .. 20; print $Ti +me::HiRes::VERSION, ' ', 1121243012.87537 1121243012.87555 1121243012.87562 1121243012.87569 1121243012.87576 1121243012.87582 1121243012.87588 1121243012.87594 1121243012.876 1121243012.87607 1121243012.87614 1121243012.8762 1121243012.87626 1121243012.87633 1121243012.87639 1121243012.87645 1121243012.87651 1121243012.87658 1121243012.87664 1121243012.8767 1.59 5.008004

      The special circumstances where the low accuracy results show up is under the debugger and in (some) evaled code. Despite spending a lot of time looking at this on 2 separate occasions, I cannot work out why Perl should produce different results under these circumstances.

      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
      "Science is about questioning the status quo. Questioning authority".
      The "good enough" maybe good enough for the now, and perfection maybe unobtainable, but that should not preclude us from striving for perfection, when time, circumstance or desire allow.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://474294]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (8)
As of 2020-10-30 13:05 GMT
Find Nodes?
    Voting Booth?
    My favourite web site is:

    Results (279 votes). Check out past polls.