Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

How to measure execution time in Perl

by gasho (Beadle)
on Jan 11, 2010 at 21:26 UTC ( [id://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:

    Benchmark

    Time

    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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (2)
As of 2024-04-16 18:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found