Thanks.

You are absolutely right. The fact is that if I were working on improving the speed of production code, I would begin with profiling. In THAT activity, there is a balance of costs between how quickly code can be developed versus how fast the code can be. I have seen cases where the fastest code is extremely hard for junior or even intermediate coders to understand. Sometime it is necessary to implement that anyway because the cost in lost time due to slower algorithms is much greater. But sometimes, the simpler, slower code is desired because it can be implemented quickly by your least experienced staff.

Alas, you missed the point of the exercise. My objective is to understand these regular expressions better. I rarely develop them, and when I do, I must have the manual for regular expressions open, in order to figure out how to develop one that meets my needs. I do not need such assistance when I deal with solving systems of linear equations, numeric quadrature, or statistical analysis. I am, in a sense, pushing myself out of my comfort zone. In this context, the benchmark scripts I show are mere devices to provide one way of evaluating the merits of the different algorithms I found or developed. And, while I do intend to modify them to work with longer strings, what I was especially hoping for is some insight into the reasons for the difference in performance and how to combine the regular expressions that trim leading and trailing white space with those that eliminate redundant white space characters within strings; or if such a combination even makes sense.

Thanks

Ted


In reply to Re^2: Question about regex performance (too small) by ted.byers
in thread Question about regex performance by ted.byers

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.