Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Find Execution time of perl script??

by madtoperl (Friar)
on Jun 05, 2006 at 05:38 UTC ( #553529=perlquestion: print w/replies, xml ) Need Help??
madtoperl has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks,

I am working in perl 5.6 and i am trying to get the execution time of perl script without using Devel::DProf module.

I dont have privilege to download modules,Is there any other way to find the execution time of perl script??

Replies are listed 'Best First'.
Re: Find Execution time of perl script??
by McDarren (Abbot) on Jun 05, 2006 at 05:58 UTC
    I dont have privilege to download modules

    You don't have permissions to write to your own home directories? ...odd.

    Is there any other way to find the execution time of perl script?

    On a *nix system, you can use the time command, eg:

    time ./ real 0m0.014s user 0m0.000s sys 0m0.010s

    Or, you can make use of the Perl time command to add timestamps at the beginning and end of your script.

    #!/usr/bin/perl -w use strict; my $start_run = time(); # all your code here my $end_run = time(); my $run_time = $end_run - $start_run; print "Job took $run_time seconds\n";

    If you want greater than 1 second accuracy, then you'll need to use Time::HiRes.

    Darren :)

      To include compile time:
      #!/usr/bin/perl -w use strict; BEGIN { our $start_run = time(); } use ... use ... # all your code here my $end_run = time(); my $run_time = $end_run - our $start_run; print "Job took $run_time seconds\n";
      No need to calculate start time: it is always available through $^T (see perlvar).

      print time - $^T;
      And for programs with so few liners, there is probably little need for use strict, use warnings, meaningful variable names, etc,. ( Some posters seem too vocal on such matters; with a little more encouragement, they might also advise on the java-way of doing things.)
        True that warnings, strict, etc. may not be entirely necessary for programs that are only a half-dozen lines long, but:
        1. It's good to display them in sample code which new initiates may emulate
        2. You never know when your basic 6-line program may start evolving into something more substantial
        3. For some of us, -wT and use strict are such habits that it's more work to exclude them than to include them
      The Anonymous Monk indicated that they did not have privilege to download modules. Nothing was said about not having permissions to write to a home directory. Everyone should know how to manually install a module in a non-standard directory as it is a FAQ, but thinking that it applies to everyone assumes a great deal.

      It is not entirely uncommon not to allow outbound internet access. The same applies to not allowing inbound FTP, SCP, etc. Oh, and access to a compiler - also not uncommon to see it restricted. These restrictions may be technical impediments or use policies that must be agreed to.

      The next comment is not directed at you specifically, but to the community in general. We are to quick to assume that someone having trouble installing modules is just ignorant of alternative directory installation and summarily dismiss them. Granted, there is usually a way to get it done but it is not so obvious that it could be included in a FAQ. Each situation is different and we should be open to helping them while still not assisting in the circumvention of whatever use policy that was agreed to.

      Cheers - L~R

Re: Find Execution time of perl script??
by Codon (Friar) on Jun 05, 2006 at 05:52 UTC
    How do you define "execution time"? Do you want to know raw CPU time the script takes? If you are on a *nix platform, you can simply 'time script' which will give you Real, User, and System CPU time (IIRC) taken by the script.

    If you want more profiling information, then you need to use a profiling tool. Devel::DProf is great for this. As far as "having privilege" to download modules, you could always download them and install them under you home directory as long as you set your PERL5LIB to point to the base install location. TIMTOWTDI.

    Ivan Heffner
    Sr. Software Engineer, DAS Lead, Inc.
Re: Find Execution time of perl script??
by jwkrahn (Monsignor) on Jun 05, 2006 at 08:14 UTC
    Perhaps you want to use Perl's built-in times function.

Re: Find Execution time of perl script??
by awohld (Hermit) on Aug 05, 2016 at 06:50 UTC
    use Timer::Runtime

    #!/usr/bin/perl use Timer::Runtime; print "hi\n";
    $ perl Started: Fri Aug 5 01:48:14 2016 hi Finished: Fri Aug 5 01:48:14 2016, elapsed time = 00:00:0 +0.000398 $

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (3)
As of 2019-02-16 00:12 GMT
Find Nodes?
    Voting Booth?
    I use postfix dereferencing ...

    Results (95 votes). Check out past polls.