Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Re: Find Execution time of perl script??

by McDarren (Abbot)
on Jun 05, 2006 at 05:58 UTC ( #553532=note: print w/replies, xml ) Need Help??

in reply to Find Execution time of perl script??

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 :)

Replies are listed 'Best First'.
Re^2: Find Execution time of perl script??
by ikegami (Pope) on Jun 05, 2006 at 06:13 UTC
    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";
Re^2: Find Execution time of perl script??
by ioannis (Abbot) on Jun 05, 2006 at 06:27 UTC
    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
        Too true.

        In fact, I use a vim file that looks like so:

        ~ cat #!/usr/bin/perl -w use strict; use Data::Dumper::Simple;

        So yes, in my case at least - it is actually more trouble for me to not use strict and warnings :)

Re^2: Find Execution time of perl script??
by Limbic~Region (Chancellor) on Jun 05, 2006 at 15:14 UTC
    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

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://553532]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (3)
As of 2019-02-17 11:45 GMT
Find Nodes?
    Voting Booth?
    I use postfix dereferencing ...

    Results (96 votes). Check out past polls.