For me, for is faster on one Perl, and slower on another. The lesson learned is that optimizations like this is version dependant and not something you should bother about when trying to speed up your program.

Benchmark: running tp_for, tp_map for at least 2 CPU seconds... tp_for: 2 wallclock secs ( 1.81 usr + 0.24 sys = 2.05 CPU) @ 11 +155.46/s (n=22891) tp_map: 3 wallclock secs ( 1.96 usr + 0.23 sys = 2.19 CPU) @ 10 +615.60/s (n=23280) Rate tp_map tp_for tp_map 10616/s -- -5% tp_for 11155/s 5% -- This is perl, v5.8.0 built for MSWin32-x86-multi-thread
Benchmark: running tp_for, tp_map for at least 2 CPU seconds... tp_for: 2 wallclock secs ( 2.02 usr + 0.28 sys = 2.30 CPU) @ 35 +695.65/s (n=82100) tp_map: 2 wallclock secs ( 1.80 usr + 0.30 sys = 2.10 CPU) @ 39 +710.48/s (n=83392) Rate tp_for tp_map tp_for 35696/s -- -10% tp_map 39710/s 11% -- This is perl, v5.8.4 built for i486-linux

ihb

See perltoc if you don't know which perldoc to read!
Read argumentation in its context!


In reply to Re^3: Improved regexp sought by ihb
in thread Improved regexp sought by myomancer

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.