in reply to Sloooooow algo in Perl

Sorry for the cryptic post. I didn't want to ask people to look at the whole body of code (which is traversing a graph, adding up dependencies). I was mainly trying to inquire whether I was using some kind of known-slow operation in there. It sounds like not, so thanks for the looks. I will hook up Time::HiRes and start timing the loops to find out what's going on. Happy Saturday..... Steve

Replies are listed 'Best First'.
Re^2: Sloooooow algo in Perl
by cog (Parson) on Mar 26, 2005 at 16:43 UTC
    Not so fast, there, pal :-)

    I was mainly trying to inquire whether I was using some kind of known-slow operation in there.

    Well, it seems you're not, but don't despair just yet. Instead, explain your code in English. Really. You're probably just using a much more complicated algorithm that your Pascal friend is...

    If you explain what you want to do, people here might be able to help you :-) (and probably feel good about it)

Re^2: Sloooooow algo in Perl
by graff (Chancellor) on Mar 27, 2005 at 06:09 UTC
    I will hook up Time::HiRes and start timing the loops

    You might want to look up Devel::Dprof instead. It's part of the core distribution, and it gives you a nice breakdown of where the time goes. In a nutshell:

    perl -d:Dprof your_script # wait 160 seconds or whatever... dprofpp
    (the "dprofpp" tool should be in the same path where perl was installed). To get the best use out of it, you might want to split up your code to put one or more of the inner loops into separate subroutines, to get better granularity on the timing analysis.

    (While breaking things up that way, who knows... you might figure out some other way to do it -- then you can use Benchmark to compare which approach is best, in case it's not immediately obvious. :)

      You might want to look up Devel::Dprof instead.
      For line-by-line profiling, I've found Devel::SmallProf very useful. It's used much the same way.

      # wait 160 seconds or whatever...
      Actually, I found with both Dprof and SmallProf that the wallclock time is significantly longer than the "profiled" time. For Dprof, I recall 5x; for SmallProf, more like 10x.

      -QM
      --
      Quantum Mechanics: The dreams stuff is made of

Re^2: Sloooooow algo in Perl
by Anonymous Monk on Mar 27, 2005 at 21:38 UTC
    What I belive that anyone wants to say (but dont know why they havent said it that clearly) is that you cant use same pseudo code for both Perl and Pascal (or any other prog. languages). These two languages are very different, and their logic is different. If you do so, like in your case, you are not using strengths of the Perl. And I find it quite common that your code is much slower than one in pascal, as that pseudo code was probably writen with Pascal style programming on mind. Shure, Perl (should not be that big problem in upcoming version 6 as it alows you to define type for a variable) is a bit slow with number crunching and lot's of loops. Post the real problem, in english, and we will see what we can do.