Re: Optimize my script



On Wed, Jul 18, 2007 at 10:17:00AM +0000, JeeBee wrote:

Thanks Paul, I should profile of course, should have thought about that.

I tried the below, but it's not quite clear what this means to me.
When I run with "./analyze.pl foo bar" the execution time is fast, so the
problem is not starting up/exiting of Perl, and I conclude it must be
inside the script somwhere.

DirHandle::BEGIN takes only 0.01 seconds, so that's not it either.
I don't see the regular expressions anywhere, unfortunately.
Is there a way to change that?

Thanks

$ perl -d:DProf ./analyze.pl traplas-example output
...
$ dprofpp
Total Elapsed Time = 1.109888 Seconds
User+System Time = 1.039888 Seconds
Exclusive Times
%Time ExclSec CumulS #Calls sec/call Csec/c Name
0.96 0.010 0.010 2 0.0050 0.0050 DirHandle::BEGIN
0.00 - -0.000 1 - - DirHandle::DESTROY
0.00 - -0.000 1 - - strict::bits
0.00 - -0.000 1 - - strict::import
0.00 - -0.000 1 - - Symbol::BEGIN
0.00 - -0.000 1 - - Symbol::gensym
0.00 - -0.000 1 - - DirHandle::read
0.00 - -0.000 1 - - DirHandle::open
0.00 - -0.000 2 - - Exporter::import
0.00 - -0.000 1 - - DirHandle::new
0.00 - 0.010 2 - 0.0050 main::BEGIN

I'm not very familiar with the profiler, but at a guess, I would say
that the profiler only counts time in subroutines, and that the majority
(all?) of your program is not in a subroutine, and over 99% of the
execution time of your program is in that code.

I see the following options:

- split your code into subroutines to gain a better understanding of
what is taking how much time

- install Devel::Cover and run
$ perl -MDevel::Cover ./analyze.pl traplas-example output
$ cover
to gain a finer grained but less accurate profiling report

- go back to guessing - you were probably right ;-)

- post your code so that other people can guess too

- buy more hardware

--
Paul Johnson - paul@xxxxxxxx
http://www.pjcj.net
.



Relevant Pages

  • Re: tic toc appears to speed up code - but it should slow it down
    ... the snippet below is the most frugal skeleton that reproduces your ... the three subroutines are these ... "fa" is three times faster with the profiler on. ...
    (comp.soft-sys.matlab)
  • Re: Speed of interfaces vs inheritance
    ... Daniel Pitts wrote: ... The OP has indicated that he suspects ... Not a profiler, unless you has access to a /far/ better profiler than I ... awkward and tricky way to measure the overall execution time, ...
    (comp.lang.java.programmer)
  • Re: Functions used in a complex code
    ... I'm using a code written by another person; in the folder of the code there are many function ... The profiler measures the execution time of functions. ... file any given function resides. ...
    (comp.soft-sys.matlab)
  • Re: Coderefs in objects: tricky questions
    ... Assuming you could create a coderef without 'sub', it would still have to be invoked as a ... subroutines, thus hurting the execution time of my script? ...
    (comp.lang.perl.misc)
  • Re: subroutine execution speed
    ... The NI documentation says that subroutines get a minimised overhead ... The execution performance of subroutines cannot be reached by ... placing this VI in a for loop (select N so, that the loop executes for a few seconds) ... check the overall execution time for different VI priorities. ...
    (comp.lang.labview)