Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
I'm trying to use Algorithm::Diff to markup the differances between two plain text sequences (one old, one new) by striking through the deleted bits and highlighting the new bits.

Here is the code:

[snip] % my @old_body = split(/\b/, $old_body); % my @new_body = split(/\b/, $new_body); % my $diff = Algorithm::Diff->new(\@old_body, \@new_body); % while ($diff->Next()) { % if ($diff->Diff()) { <span class="old_text"> % foreach ($diff->Items(1)) { <% display_pre($_) %> % } </span> <span class="new_text"> % foreach ($diff->Items(2)) { <% display_pre($_) %> % } </span> % } else { % foreach ($diff->Same()) { <% display_pre($_) %> % } % } % } [snip]

It seems to work really quickly sometimes and really slowly other times, which is odd.

I Devel::Dprofed it and got the following:

%Time ExclSec CumulS #Calls sec/call Csec/c Name 47.5 46.88 46.888 123881 0.0000 0.0000 Algorithm::Diff::_replace +NextLarge rWith 17.3 17.05 64.094 1 17.056 64.093 Algorithm::Diff::_longest +CommonSub 5 sequence 0.31 0.304 0.304 16299 0.0000 0.0000 HTML::Mason::Request::pri +nt 0.16 0.153 64.717 1 0.1528 64.716 HTML::Mason::Request::cal +l_next 0.11 0.106 0.154 5418 0.0000 0.0000 HTML::Mason::Commands::BE +GIN 0.09 0.086 0.101 1 0.0855 0.1010 Algorithm::Diff::_withPos +itionsOfI nInterval 0.07 0.070 0.070 3 0.0233 0.0233 HTML::Mason::Interp::appl +y_escapes 0.06 0.063 0.063 8911 0.0000 0.0000 Algorithm::Diff::__ANON__ 0.05 0.050 0.060 7 0.0072 0.0086 HTML::Mason::Request::com +p 0.04 0.038 0.038 5394 0.0000 0.0000 HTML::Entities::encode_en +tities 0.03 0.030 64.947 1 0.0301 64.947 HTML::Mason::ApacheHandle +r::handle 1 r 0.03 0.030 64.124 1 0.0300 64.123 Algorithm::Diff::LCSidx 0.02 0.020 0.020 1 0.0200 0.0200 DBI::connect 0.01 0.010 0.010 9 0.0011 0.0011 vars::import 0.01 0.010 0.010 1 0.0100 0.0100 Apache::Session::DESTROY

Any ideas as to what is causing the lag?

-Andrew.


Andrew Tomazos  |  andrew@tomazos.com  |  www.tomazos.com

In reply to Optimizing Algorithm::Diff by tomazos

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (4)
As of 2024-03-29 00:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found