Beefy Boxes and Bandwidth Generously Provided by pair Networks Bob
XP is just a number
 
PerlMonks  

Getting microseconds

by hotshot (Prior)
on Aug 26, 2003 at 08:22 UTC ( #286621=perlquestion: print w/ replies, xml ) Need Help??
hotshot has asked for the wisdom of the Perl Monks concerning the following question:

Hello all!

I need to write in perl a function that will return the microsecond, in similar to C function gettimeofday() that returns a struct with microsecond (timeval.tv-usec). Anyone has a code suggestion or can refer me to a useful module for that?

Thanks

Hotshot

Comment on Getting microseconds
Re: Getting microseconds
by edan (Curate) on Aug 26, 2003 at 08:28 UTC
Re: Getting microseconds
by Zaxo (Archbishop) on Aug 26, 2003 at 08:36 UTC

    Actual time resolution to that accuracy is chancy on most platforms. As recommended, Time::HiRes is a good bet, but most platforms will not guarantee any absolute time better than the schedulers time slice, or jiffy. If you need better, check around for 'real time' kernels.

    After Compline,
    Zaxo

Re: Getting microseconds
by thunders (Priest) on Aug 26, 2003 at 14:23 UTC

    you could use Inline::C. I'm not really a C programmer, but something like this should print the result of that C call.

    print currentTimeMillis(); use Inline C => <<'END_OF_C_CODE'; #include <sys/time.h> long currentTimeMillis() { long t; struct timeval tv; gettimeofday(&tv, 0); t = tv.tv_usec; return t; } END_OF_C_CODE

      Reason: thunders Troll

      For more information on this node visit: this

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (8)
As of 2014-04-21 12:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (495 votes), past polls