ChopperCharles has asked for the wisdom of the Perl Monks concerning the following question:

I need the equivalent of GetTickCount in perl. Doesn't have to be system up time, can also be milliseconds since epoch.

Thanks.

Charles.

Replies are listed 'Best First'.
Re: Equivalent of GetTickCount() in perl?
by GrandFather (Saint) on Nov 01, 2011 at 20:09 UTC

    my ($epochSecs, $epochUSecs) =Time::HiRes::gettimeofday ();

    True laziness is hard work
      Had no luck (unrecognized sub) w/Perl 5.12, Time::HiRes -- but this code merely needs conversion of seconds to milliseconds:
      "use Time::HiRes qw(gettimeofday);$t0=gettimeofday();print \"Seconds M +iliseconds: $t0\";" Seconds Miliseconds: 1320179894.348 <c>perl -MTime::HiRes -e"print $Time::HiRes::VERSION;" 1.9724 perl -v This is perl 5, version 12, subversion 3 (v5.12.3) built for MSWin32-x +86-multi-thread (with 9 registered patches, see perl -V for more detail) Copyright 1987-2010, Larry Wall Binary build 1204 [294330] provided by ActiveState http://www.ActiveSt +ate.com Built Feb 9 2011 14:38:22

        Odd. The following works fine for me with and ActiveState install of Perl 5.10.1 on Windows 7:

        use warnings; use strict; use Time::HiRes; my ($epochSecs, $epochUSecs) = Time::HiRes::gettimeofday (); print "$epochSecs $epochUSecs $Time::HiRes::VERSION";

        Prints:

        1320191917 602197 1.9724

        and worked for version 1.9719 of Time::HiRes too.

        True laziness is hard work
Re: Equivalent of GetTickCount() in perl?
by BrowserUk (Patriarch) on Nov 01, 2011 at 21:00 UTC

    If you have ActiveState Perl, it is built-in:

    c:\test>perl -E"say Win32::GetTickCount() for 1 .. 10" 2554402647 2554402647 2554402647 2554402647 2554402647 2554402662 2554402662 2554402662 2554402662 2554402662

    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      Most any win32 perl has it

        That's cool, but as I didn't know for sure, I stated what I knew to be so.