I think you led me to the right direction: nanosecond.

I used the following script and compared the results with the original code. When averaging differences of 100 seconds (each script), the original comes out a bit better, but when averaging diffs of 300 seconds, the new script is better.

use strict; use warnings; use Math::BigFloat; use Time::HiRes qw(gettimeofday sleep nanosleep); ... sub old_script { my $max = $_[0]; my @time_test; my $start = time(); for (my $i = 0; $i < $max; $i++) { $start += 1; sleep $start - time(); $time_test[$i] = Math::BigFloat->new(sprintf("%d.%06d", gettim +eofday)); } return @time_test; } sub new_script { my $max = $_[0]; my @time_test; for (my $i = 0; $i < $max; $i++) { nanosleep (1000000000); $time_test[$i] = Math::BigFloat->new(sprintf("%d.%06d", gettim +eofday)); } return @time_test; }

The averages:

# 100 s each script old_script_values_avg : 1.000479131313131313131313131313131313131 new_script_values_avg : 1.001016101010101010101010101010101010101 # 300 s each script old_script_values_avg : 0.9974391538461538461538461538461538461538 new_script_values_avg : 1.000457983277591973244147157190635451505

I believe I cannot get better results without atomic clock. Correct me if I’m wrong.

Anyway, thanks for the help and your time!


In reply to Re^4: The most precise second (timer) by tukusejssirs
in thread The most precise second (timer) by tukusejssirs

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.