develooper Front page | perl.perl5.porters | Postings from June 2016

[perl #128349] Benchmark module doesn't use documented format fortimes

Thread Next
From:
Linda Walsh
Date:
June 8, 2016 22:30
Subject:
[perl #128349] Benchmark module doesn't use documented format fortimes
Message ID:
rt-4.0.18-13378-1465424987-976.128349-75-0@perl.org
# New Ticket Created by  Linda Walsh 
# Please include the string:  [perl #128349]
# in the subject line of all future correspondence about this issue. 
# <URL: https://rt.perl.org/Ticket/Display.html?id=128349 >


I looked at the Benchmark modules and it seems the bugs for it are in the perl5 category -- I guess that means it's part of 'Core'?

Anyway, that's why I'm reporting this here.

This is using the Inst_Version 1.13 distributed with 5.16.3 -- I.E. this may already be fixed, not easily testable at this point.

But using a call to Benchmark::timestr:

my $time_str	= Benchmark::timestr($diff, 'all', '20.9F');
print "time_str=$time_str\n";

I got:
time_str=4.36661 wallclock secs (         0.010000000 usr          0.000000000 sys +          0.390000000 cusr          1.460000000 csys =          1.860000000 CPU)

note, at the top, I have:
use Benchmark qw(:all :hireswallclock);

So, it should be giving microsecond accuracy.  Drilling down
to /usr/include/bits/time.h, I see:

/* A time value that is accurate to the nearest
   microsecond but also has a range of years.  */
struct timeval
  {
    __time_t tv_sec;    /* Seconds.  */
    __suseconds_t tv_usec;  /* Microseconds.  */
  };

So the cpu seconds only appear to be accurage to 100's of a second, but clock_info on my system shows:

> clock_info
                    Name:        Current value  Resolution
          CLOCK_REALTIME: 1465424223.084752159        1 ns
         CLOCK_MONOTONIC:    8954268.857661674        1 ns
     CLOCK_MONOTONIC_RAW:    8953806.267750053        1 ns
CLOCK_PROCESS_CPUTIME_ID:          0.001527207        1 ns
 CLOCK_THREAD_CPUTIME_ID:          0.001535497        1 ns
     CLOCK_MONOTONIC_RAW:    8953806.267778595        1 ns
   CLOCK_REALTIME_COARSE: 1465424223.083592029        1 ms
  CLOCK_MONOTONIC_COARSE:    8954268.856492955        1 ms
          CLOCK_BOOTTIME:    8954268.857743661        1 ns
    CLOCK_REALTIME_ALARM: 1465424223.084872396        1 ns
    CLOCK_BOOTTIME_ALARM:    8954268.857790177        1 ns
CLOCK_SGI_CYCLE: Invalid argument
               CLOCK_TAI: 1465424223.084927434        1 ns

---
(My cpu clock is set to 1000Hz:
> zgrep CONFIG_HZ /proc/config.gz 
# CONFIG_HZ_PERIODIC is not set
# CONFIG_HZ_100 is not set
# CONFIG_HZ_250 is not set
# CONFIG_HZ_300 is not set
CONFIG_HZ_1000=y
CONFIG_HZ=1000 )

so that would make it logical that cpu times might only be accurate to 1ms, but it doesn't appear to have used the 20.9F format for the realtime either.

I was a bit surprised by the output -- I expected a space-separated string of 5 numbers (for real, parent process and children processes).  I must have not been clear on the documentation about the extra verbiage being included.

Side question: Is there anyway just to get back the array of 5 numbers so no conversions are necessary -- especially since the conversion thing doesn't seem to work right?  (thought 20.9F would give me double precision (64-bits?)...  thought I'd at least get back more than centisecs...  

Note clock_info does *seem* to return time in nanoseconds...but haven't investigated those sources (not that I need such accuracy, but was trying, simply, to store the full accuracy of what Benchmark had stored internally -- thus my sideQ about a way to get values w/o conversions or breaking into the Benchmark object).

At the very least, if that accuracy is the best that is possible, that might be mentioned in the manpage, though it's pretty clearly not using the precision for the real-time clock.





Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About