Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

How to measure execution time in Perl

by gasho (Beadle)
on Jan 11, 2010 at 21:26 UTC ( #816782=perlquestion: print w/replies, xml ) Need Help??

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

Dear Monks, Is there a perl function that measures execution time of Perl script , Thanks?
StartToMesure perl code StopToMesure print "ExecutionTIme"
(: Life is short enjoy it :)

Replies are listed 'Best First'.
Re: How to measure execution time in Perl
by kennethk (Abbot) on Jan 11, 2010 at 21:29 UTC
    CPAN is your friend:



    In particular, see Benchmark and Time::HiRes. A quick and dirty solution is also the built-in time, which will give you second-level granularity, a la:

    #!/usr/bin/perl use strict; use warnings; my $start = time; # Do stuff my $duration = time - $start; print "Execution time: $duration s\n";
Re: How to measure execution time in Perl
by moritz (Cardinal) on Jan 11, 2010 at 21:54 UTC
    You might also be interested in using a profile. Devel::NYTProf is a very good and informative profiler, it makes it quite easy to spot bottlenecks in your programs.
    Perl 6 - links to (nearly) everything that is Perl 6.

      I'd just like to add that Devel::NYTProf supports multiple ways to measure the time it takes to run some code. The documentation is great, and it covers the benefits and problems associated with each profiling method. You can learn a lot without ever using the module.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://816782]
Approved by kennethk
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (3)
As of 2023-03-28 21:32 GMT
Find Nodes?
    Voting Booth?
    Which type of climate do you prefer to live in?

    Results (69 votes). Check out past polls.