Consider also that regex are so optimezed so that the second option, using substr, 'may' become a 'little' faster then regexes only when you operate against huge data in a foreach loop:
#10 fields in the array iterating over: Benchmark: running Regex, Substr for at least 4 CPU seconds... Regex: 4.58121 wallclock secs ( 4.18 usr + 0.02 sys = 4.20 CPU) + @ 3968640.46/s (n=16656384) Substr: 4.38291 wallclock secs ( 4.32 usr + 0.00 sys = 4.32 CPU) + @ 3927240.92/s (n=16969608) #100 fields Benchmark: running Regex, Substr for at least 4 CPU seconds... Regex: 4.56133 wallclock secs ( 4.12 usr + -0.01 sys = 4.11 CPU) + @ 3995786.36/s (n=16402703) Substr: 4.29298 wallclock secs ( 4.03 usr + 0.00 sys = 4.03 CPU) + @ 4190639.34/s (n=16871514) #1000 fields ###Regex is faster!! (tested 5 times) Benchmark: running Regex, Substr for at least 4 CPU seconds... Regex: 4.1849 wallclock secs ( 4.03 usr + 0.01 sys = 4.04 CPU) +@ 4139558.42/s (n=16723816) Substr: 5.5707 wallclock secs ( 4.26 usr + 0.00 sys = 4.26 CPU) +@ 3843370.27/s (n=16368914) #10000 fields Benchmark: running Regex, Substr for at least 4 CPU seconds... Regex: 4.87697 wallclock secs ( 4.68 usr + 0.00 sys = 4.68 CPU) + @ 3600221.37/s (n=16849036) Substr: 4.21117 wallclock secs ( 3.99 usr + 0.03 sys = 4.02 CPU) + @ 4352730.93/s (n=17519742) #BUT ALSO 10000 fields Benchmark: running Regex, Substr for at least 4 CPU seconds... Regex: 4.32358 wallclock secs ( 4.09 usr + -0.02 sys = 4.07 CPU) + @ 3946014.74/s (n=16064226) Substr: 4.44415 wallclock secs ( 4.10 usr + 0.03 sys = 4.13 CPU) + @ 3892862.84/s (n=16093095)
L*
There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

In reply to Re: syntax question (some Bench) by Discipulus
in thread syntax question by rruser

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.