Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

I had tried Time::HiRes::clock(), but that gives the same resolution as times. So I thought that was a dead end.

However, I went back and read again. There are Time::HiRes::clock_gettime($which) and Time::HiRes::getres($which). Where the $which is the name of a POSIX high resolution timer. I confess I had assumed that this was wall-clock.

The POSIX timer CLOCK_REALTIME claims a resolution of 1E-9 on my machine. Hurrah :-) However, that is wall-clock. Boo :-(

The Time::HiRes hints that there may be other timers... so, I went digging in the POSIX documentation. I found CLOCK_PROCESS_CPUTIME_ID, which does what the name suggests, and also claims a resolution of 1E-9 on my machine. Hurrah !

Conclusion, yes: turns out that Time::HiRes is the answer -- thank you. To know that, however, you need to know that:

  • there is a "clock" called CLOCK_PROCESS_CPUTIME_ID -- provided you have a POSIX compliant system, and _POSIX_CPUTIME is defined (which is discovered using getconf).
  • that you use can import that name from Time::HiRes and use it with Time::HiRes::clock_gettime($which) and Time::HiRes::getres($which) to access the timer.
  • there is also a "clock" called CLOCK_THREAD_CPUTIME_ID, which is available if _POSIX_THREAD_CPUTIME is defined.
So, for my purposes:
use Time::HiRes qw(clock_gettime CLOCK_PROCESS_CPUTIME_ID) ; $start = clock_gettime(CLOCK_PROCESS_CPUTIME_ID) ; # replaces $start + = (times)[0] ... $end = clock_gettime(CLOCK_PROCESS_CPUTIME_ID) ; # replaces $end + = (times)[0]
is the trick -- which I note in case it's of use to anyone like me who knew nothing of it until today.


In reply to Re^2: Anything better than 'times' ? by gone2015
in thread Anything better than 'times' ? by gone2015

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (3)
As of 2024-04-25 20:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found