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. Advertising

  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. Advertising

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. Adam
    Replies:
    2
    Views:
    97
    Michele Dondi
    Nov 17, 2004
  2. mastermagrath
    Replies:
    4
    Views:
    418
    robic0
    Dec 1, 2005
  3. Mark Seger
    Replies:
    1
    Views:
    102
    Mark Seger
    Sep 28, 2006
  4. Mark Seger
    Replies:
    6
    Views:
    109
    Martijn Lievaart
    Apr 15, 2008
  5. Mark Seger

    Time::HiRes hell...

    Mark Seger, Jul 1, 2008, in forum: Perl Misc
    Replies:
    6
    Views:
    198
    Mark Seger
    Jul 1, 2008
Loading...

Share This Page