Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

timestamp in milliseconds

by mosh (Scribe)
on Jul 12, 2005 at 15:17 UTC ( [id://474293]=perlquestion: print w/replies, xml ) Need Help??

mosh has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks !

Is there any build in timestamp function in Perl ?
I'm usually use time() command, but now I need something that display it in milliseconds...

Other ideas will be accepted gladly.

Thanks,
Mosh.

Replies are listed 'Best First'.
Re: timestamp in milliseconds
by gryphon (Abbot) on Jul 12, 2005 at 15:19 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.
Re: timestamp in milliseconds
by Limbic~Region (Chancellor) on Jul 12, 2005 at 15:21 UTC
Re: timestamp in milliseconds
by Anonymous Monk on Mar 26, 2013 at 04:45 UTC
    Thanks very helpful!!!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://474293]
Approved by marto
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (4)
As of 2024-03-29 12:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found