Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Is foreach split Optimized?

by Marshall (Canon)
on Jul 09, 2017 at 11:32 UTC ( [id://1194597]=note: print w/replies, xml ) Need Help??


in reply to Is foreach split Optimized? (Update: No.)

I am curious about your benchmark program.
With my $str = "\nFoo\n\nBar Quz\nBaz\nx" x 500000;
I get:
5.020002 (warning: too few iterations for a reliable count) (warning: too few iterations for a reliable count) (warning: too few iterations for a reliable count) s/iter index regex split index 26.5 -- -61% -66% regex 10.3 158% -- -12% split 9.05 193% 13% --
which basically means that the results don't matter.

Code as with my $str = "\nFoo\n\nBar Quz\nBaz\nx" x 50000;
Your benchmark default.

5.020002 (warning: too few iterations for a reliable count) (warning: too few iterations for a reliable count) Rate index regex split index 1.16/s -- -21% -34% regex 1.47/s 27% -- -16% split 1.74/s 51% 19% --
I am not sure what this means if anything.

Replies are listed 'Best First'.
Re^2: Is foreach split Optimized?
by haukex (Archbishop) on Jul 09, 2017 at 11:44 UTC
    (warning: too few iterations for a reliable count)

    You can get rid of those warnings by increasing the runtime by saying e.g. cmpthese(-5, .... I did fiddle with it quite a bit, adjusting the string length, runtime, etc. and the results were always consistent that split was fastest by a significant margin.

      Interesting:
      5.020002 Rate index regex split split2 index 1.17/s -- -23% -35% -43% regex 1.51/s 29% -- -16% -26% split 1.79/s 53% 18% -- -12% split2 2.03/s 74% 35% 14% --
      split2 uses tr/// instead of regex s///...

        I'm investigating the speed of iterating through the string, not how it gets processed afterwards, which is why the loop bodies are all the same. So to make the benchmark be fair again, you'd have to make the same change in all the loops. I just added that bit of s/// code to provide a somewhat realistic loop body (Update: or rather, a placeholder for the actual loop body, which manipulates the $line a whole lot more and whose output is much more complex than one line of output per line of input), and as a (likely misguided) attempt to prevent for my $line (@x) { push @lines, $line; } from being optimized to @lines = @x;.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1194597]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (9)
As of 2024-04-23 21:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found