Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Funny, I get
q( Benchmark: timing 100000 iterations of C-style, push... C-style: 2 wallclock secs ( 3.20 usr + 0.00 sys = 3.20 CPU) @ 31 +279.32/s (n=100000) push: 3 wallclock secs ( 2.63 usr + 0.09 sys = 2.72 CPU) @ 36 +724.20/s (n=100000)
I even went so far as to gather:
#These "cripple" C-style and push to make it a fair fight, by reinitia +lizing the array each time Benchmark: timing 100000 iterations of C-style, destroy, push... C-style: 4 wallclock secs ( 3.88 usr + 0.00 sys = 3.88 CPU) @ 25 +779.84/s (n=100000) destroy: 2 wallclock secs ( 2.25 usr + 0.08 sys = 2.33 CPU) @ 42 +918.45/s (n=100000) push: 4 wallclock secs ( 3.24 usr + 0.07 sys = 3.31 CPU) @ 30 +184.12/s (n=100000) #These do not: Benchmark: timing 1000000 iterations of C-style, destroy, push... C-style: 34 wallclock secs (32.64 usr + 0.00 sys = 32.64 CPU) @ 30 +633.50/s (n=1000000) destroy: 24 wallclock secs (22.72 usr + 0.81 sys = 23.53 CPU) @ 42 +498.94/s (n=1000000) push: 2 wallclock secs ( 2.38 usr + 0.00 sys = 2.38 CPU) @ 41 +9463.09/s(n=1000000) );
@in = (1,2,3,4,5,6,7,8,9,0); use Benchmark; timethese(100000, { 'C-style' => '#@in = (1,2,3,4,5,6,7,8,9,0); for my $i ( 0 .. $#in ) { $i % 2 ? $out2[int($i/2)] = $in[$i] : $out1[$i/2] = $in[$ +i]; }', 'push' => '#@in = (1,2,3,4,5,6,7,8,9,0); for my $i ( 0 .. $#in ) { $i % 2 ? push @out2, $in[$i] : push @out1, $in[$i]; }', 'destroy' => '@in = (1,2,3,4,5,6,7,8,9,0); while( @in ){ push @out1, shift(@in); push @out2, shift(@in); }' });
Statistics can say lots of things
q( #These "cripple" C-style and push to make it a fair fight, by reinitia +lizing the array each time C-style: 1 wallclock secs ( 0.57 usr + 0.04 sys = 0.60 CPU) +@ 16528.93/s (n=10000) destroy: 337 wallclock secs (325.85 usr + 0.28 sys = 326.13 CPU) +@ 30.66/s (n=10000) push: 1033 wallclock secs (983.44 usr + 0.85 sys = 984.30 CPU) +@ 10.16/s (n=10000) #These do not Benchmark: timing 10000 iterations of C-style, destroy, push... C-style: 1 wallclock secs ( 0.47 usr + 0.03 sys = 0.51 CPU) @ + 19762.85/s (n=10000) destroy: 339 wallclock secs (321.60 usr + 0.32 sys = 321.92 CPU) @ + 31.06/s (n=10000) push: 655 wallclock secs (641.02 usr + 0.54 sys = 641.56 CPU) @ + 15.59/s (n=10000) ); open OUT, ">/dev/null"; select(OUT); $|++; select(STDOUT); @in = (1,2,3,4,5,6,7,8,9,0); use Benchmark; timethese(10000, { 'C-style' => '#@in = (1,2,3,4,5,6,7,8,9,0); for my $i ( 0 .. $#in ) { $i % 2 ? $out2[int($i/2)] = $in[$i] : $out1[$i/2] = $in[$ +i]; } print OUT @out1,"\n"; print OUT @out2,"\n";', 'push' => '#@in = (1,2,3,4,5,6,7,8,9,0); for my $i ( 0 .. $#in ) { $i % 2 ? push @out2, $in[$i] : push @out1, $in[$i]; } print OUT @out1,"\n"; print OUT @out2,"\n";', 'destroy' => '@in = (1,2,3,4,5,6,7,8,9,0); while( @in ){ push @out1, shift(@in); push @out2, shift(@in); } print OUT @out1,"\n"; print OUT @out2,"\n";' });

--
perl -pe "s/\b;([st])/'\1/mg"


In reply to Re: Answer: How can I skip an element in an array whilst reading... by belg4mit
in thread How can I skip an element in an array whilst reading... by Blanco

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (7)
As of 2024-04-19 07:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found