Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Getting microseconds

by hotshot (Prior)
on Aug 26, 2003 at 08:22 UTC ( [id://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

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,
    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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
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?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (2)
As of 2024-04-20 03:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found