in reply to Context search term highlighting - Perl is too slow

Offhand, I don't see anything that looks overtly slow in the code. I wish you'd have presented this as a function with clear arguments/return values so I could throw some Real Life data at it and see how it behaves.

At times, there's loops nested three deep to do your processing. For me, that's an optimization red flag saying "you're probably going about this the wrong way." Is that necessary? Is there a way to approach this without the looping? (Again, I wish we had a function and some data to play with.)

  • Comment on Re: Context search term highlighting - Perl is too slow

Replies are listed 'Best First'.
Re: Re: Context search term highlighting - Perl is too slow
by moseley (Acolyte) on Dec 20, 2001 at 04:01 UTC
    Can the nested loops be avoided? That's a good question.

    The problem is that I have to map between the words I'm comparing and the original "un-modified" text.

    Anyway, here's an example that runs.

    http://hank.org/modules/PhraseTest.pm

    (I think PerlMonk's wrapping code is too agressive in code blocks)

    > dprofpp -u -p PhraseTest.pm Total Elapsed Time = 0.506468 Seconds User Time = 0.508234 Seconds Exclusive Times %Time ExclSec CumulS #Calls sec/call Csec/c Name 61.0 0.310 0.430 30 0.0103 0.0143 PhraseHighlight::highligh +t_text 15.7 0.080 0.080 30 0.0027 0.0027 PhraseHighlight::build_hi +ghlighted _text 5.90 0.030 0.030 30 0.0010 0.0010 PhraseHighlight::substitu +e_highlig ht 3.94 0.020 0.020 15 0.0013 0.0013 Text::Wrap::wrap 1.97 0.010 0.010 30 0.0003 0.0003 PhraseHighlight::join_wor +ds 1.97 0.010 0.010 1 0.0100 0.0100 warnings::BEGIN 1.97 0.010 0.020 1 0.0100 0.0200 vars::BEGIN 1.97 0.010 0.010 2 0.0050 0.0050 PhraseHighlight::BEGIN 0.00 0.000 -0.000 2 0.0000 - vars::import 0.00 0.000 -0.000 3 0.0000 - Text::Tabs::BEGIN 0.00 0.000 -0.000 2 0.0000 - result::BEGIN 0.00 0.000 -0.000 4 0.0000 - constant::BEGIN 0.00 0.000 -0.000 1 0.0000 - warnings::register::impor +t 0.00 0.000 -0.000 2 0.0000 - warnings::register::mkMas +k 0.00 0.000 -0.000 1 0.0000 - strict::unimport
    Thanks,