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

#!/fellow/monks.pl

I need to calculate how long it takes to do a particular task. The attached sample works for second intervals, however, I need to be able to count down to the milli second. How can I achieve that ?

#!/usr/bin/perl $start = time; sleep(2); #or some other crazy pieces of code $end = time; $length = $end - $start; print "It took us $length seconds to do the job.\n";

Thanks!

|\/| _. _ _  ._
|  |(_|_>_>\/| |
           /

Replies are listed 'Best First'.
Re: Count the milliseconds
by adrianh (Chancellor) on Mar 01, 2004 at 09:01 UTC
Re: Count the milliseconds
by BrowserUk (Patriarch) on Mar 01, 2004 at 09:29 UTC

    If you like nicely formatted, potted reports, take a look at Benchmark::Timer


    Examine what is said, not who speaks.
    "Efficiency is intelligent laziness." -David Dunham
    "Think for yourself!" - Abigail
Re: Count the milliseconds
by meetraz (Hermit) on Mar 01, 2004 at 21:52 UTC
    And, if you're working on a Windows system, you can use the Win32::GetTickCount() function, like this:

    $start = Win32::GetTickCount(); sleep(2); #or some other crazy pieces of code $end = Win32::GetTickCount(); $length = $end - $start; print "It took us $length milliseconds to do the job.\n";