Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Oops, thank you. I missed that one because I downloaded the solutions by crawling the displaycode links on the thread page and he didn't put his entry in CODE tags.

It works correctly and therefor qualifies, but I only get about 340 iterations/s for it. That puts it next to Limbic~Region's entry in my chart. I'm not surprised, as his code is quite complex and involves a true for(;;) loop (relatively slow in Perl). Fast code in Perl means as few opcodes as possible and letting builtins do work implicitly as much as possible. (See GRT, f.ex.)

That is how I arrived at my second version. I copied the first version, ripped everything except the XOR out of the loop, and started benchmarking them against each other as I tried to accelerate extraction of null runs from the bitmask and rotation of the reverse string. Every single operation I added to the (non-functional, skeletal) second version had a dramatic impact on speed. Whatever I did, I found nothing with which to improve upon while( /\0{3,}/g ) { } and substr+chop. I only managed to get a speedup when I constrained the match further so that the regex engine isn't exited to drop into the loop body for null runs that are too short to be candidates. Apparently, avoiding that penalty by skipping matches implicitly more than makes up for the additional cost of having to compile the regex multiple times, which skipping them explicitly didn't require.

The version and compile-time flags of the Perl in use probably matter to some degree, as well.

Makeshifts last the longest.


In reply to Re^3: Finding longest palindrome from a string (optimizing Perl) by Aristotle
in thread Finding longest palindrome from a string by BUU

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 pondering the Monastery: (3)
As of 2024-04-16 18:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found