Oh well, you are right about that: the difference is too low to be noticable for normal use. I was just picking up merlyn's glove ;-}.

I just added the cmpthese stats when I saw your posting. Take a look at them. Some nitbits: I would call the swab 'insert'. But that can be done by substr as well... benchmarks coming up....

Rate inssub regmap regex fixreg substr inssub 13.7/s -- -95% -97% -97% -97% regmap 260/s 1800% -- -34% -35% -47% regex 395/s 2784% 52% -- -1% -20% fixreg 398/s 2809% 53% 1% -- -19% substr 491/s 3483% 89% 24% 23% --
That insert must be *really* inefficient :-)

Jeroen
"We are not alone"(FZ)

Let me add the new code:

use Benchmark; undef $/; open DATA, "/home/jeroen/texs/review/reviewnew.tex" or die $!; $str = <DATA>; open DUMP, ">/dev/null"; $result = timethese( -5, { 'regex' => sub { $a = $str; $b = ''; $b .= "$1\n" while $a=~/\G(.{1,80})/gs; print DUMP "$b"; }, 'regmap' => sub { $a = $str; $b = ''; print DUMP map "$_\n", $a=~/\G(.{1,80})/gs; }, 'fixreg'=> sub { $a = $str; $b = ''; $b .= "$1\n" while $a=~/\G(.{1,80})/gos; print DUMP "$b"; }, 'substr' => sub { $a = $str; $b=''; $b .= substr( $a, 0, 80, '')."\n" while length($a) >80; print DUMP "$b$a"; }, 'inssub' => sub { $a = $str; $idx = 0; substr( $a, $idx+=81, 0)="\n" while $idx< (length( $a) - 80 ); print DUMP "$a"; } }, 'none'); Benchmark::cmpthese($result);

In reply to Re:{6} how do I line-wrap while copying to stdout? by jeroenes
in thread how do I line-wrap while copying to stdout? by ams

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.