Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

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 ( Anyone has a code suggestion or can refer me to a useful module for that?



Replies are listed 'Best First'.
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,

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

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (3)
As of 2023-03-24 15:59 GMT
Find Nodes?
    Voting Booth?
    Which type of climate do you prefer to live in?

    Results (61 votes). Check out past polls.