accuracy of Time::HiRes

Discussion in 'Perl Misc' started by John, Jun 27, 2008.

  1. John

    John Guest

    Hi

    use Time::HiRes qw (gettimeofday);
    my ($secs,$milliseconds)=gettimeofday();
    my $trans="$secs$milliseconds"; # 10 digits and 6 digits

    Sometimes the length of $trans is 16 but sometimes it is 15.
    Shouldn't it be 16 always?

    Regards
    John
     
    John, Jun 27, 2008
    #1
    1. Advertisements

  2. John

    John Guest

    "Anonymous coward" <> wrote in message
    news:bdb84$48655840$89e0e08f$...
    > On Fri, 27 Jun 2008 21:38:39 +0100, John wrote:
    >
    >> Hi
    >>
    >> use Time::HiRes qw (gettimeofday);
    >> my ($secs,$milliseconds)=gettimeofday(); my $trans="$secs$milliseconds";
    >> # 10 digits and 6 digits
    >>
    >> Sometimes the length of $trans is 16 but sometimes it is 15. Shouldn't
    >> it be 16 always?
    >>
    >> Regards
    >> John

    >
    > The length of microseconds (not milliseconds) will be 5 digits one out of
    > ten times, because it's value is less than 100000 microseconds. In one
    > out of a hundred times it will be 4 digits, etc. If you rely on the
    > length of it, you should probably use sprintf.
    >
    > Regards,
    >
    > Leon Timmermans


    Hi

    Of course, I see that now. I need the length to create a unique number of
    standard length. sprintf will do that.
    Many thanks.

    Regards
    John
     
    John, Jun 28, 2008
    #2
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Spitfire
    Replies:
    12
    Views:
    1,545
    CBFalconer
    Mar 13, 2007
  2. Adam
    Replies:
    2
    Views:
    170
    Michele Dondi
    Nov 17, 2004
  3. mastermagrath
    Replies:
    4
    Views:
    805
    robic0
    Dec 1, 2005
  4. Mark Seger
    Replies:
    1
    Views:
    199
    Mark Seger
    Sep 28, 2006
  5. Mark Seger
    Replies:
    6
    Views:
    195
    Martijn Lievaart
    Apr 15, 2008
  6. Mark Seger

    Time::HiRes hell...

    Mark Seger, Jul 1, 2008, in forum: Perl Misc
    Replies:
    6
    Views:
    312
    Mark Seger
    Jul 1, 2008
  7. VK
    Replies:
    21
    Views:
    378
    Thomas 'PointedEars' Lahn
    Dec 10, 2005
  8. Tobiah

    Real time event accuracy

    Tobiah, May 9, 2012, in forum: Python
    Replies:
    2
    Views:
    423
    Tobiah
    May 9, 2012
Loading...