This must be OS dependent or something... (hard to say as you didnt post the output). On my system print with no cache is much faster:

open my $zap, ">", "NULL:"; use Benchmark "cmpthese"; cmpthese -10, { every => sub { for (1..100) { print $zap $_ } }, tens => sub { my $x; for (1..100) { $x .= $_; unless ($x % 10) { print $zap $x; $x=""; } } print $zap $x if length $x; }, } __END__ # modfied code as posted above (5.6.1 on W2k) Rate tens every tens 1159/s -- -90% every 11285/s 874% -- # original code (5.6.1 on W2k) Rate tens every tens 1124/s -- -90% every 11219/s 899% -- # 5.8.4 (XP) Rate tens every tens 8305/s -- -73% every 30329/s 265% -- # 5.8.6 No Implicit Sys (XP) Rate tens every tens 9655/s -- -68% every 29755/s 208% --

At least on Win32 it would seem just using print is much faster.... I guess this could be an example of what Steve Hay was talking about with Win32's realloc being crap and that it makes concatenation unecessarily slow. Update: No, that doesnt make sense, I just tried it with two different perl versions on two different win32 boxes and "every" won every one of them....

Ignore this for now, its got a bug: "NUL" not "NULL:",as ysth pointed out. Ill redo it when i have access to all those perl versions again

---
demerphq


In reply to Re^4: perl performance vs egrep by demerphq
in thread perl performance vs egrep by dba

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.