<html><body><div style="color:#000; background-color:#fff; font-family:lucida console, sans-serif;font-size:13px"><div class="" style="">Benchmark is the bomb.  I have used it for exactly the kind of comparisons that Wade did in a different context: comparing various Perl user agents against LWP::UserAgent. </div><div class="" style=""><br class="" style=""></div><div class="" style="color: rgb(0, 0, 0); font-size: 13px; font-family: 'lucida console', sans-serif; background-color: transparent; font-style: normal;">Talk recommendations and/or tl;dr - Use HTTP::Tiny if possible (especially if your base Perl is 5.14 or later), or LWP::Curl if you feel the need for speed and can tolerate XS in your dependencies. </div><div class="" style=""><br class="" style=""></div><div class="" style="color: rgb(0, 0, 0); font-size: 13px; font-family: 'lucida console', sans-serif; background-color: transparent; font-style: normal;">Code: <a
 href="https://github.com/mrallen1/perl-UA-Bench" class="" style="">https://github.com/mrallen1/perl-UA-Bench</a></div><div class="" style="color: rgb(0, 0, 0); font-size: 13px; font-family: 'lucida console', sans-serif; background-color: transparent; font-style: normal;"> </div><div class="" style="color: rgb(0, 0, 0); font-size: 13px; font-family: 'lucida console', sans-serif; background-color: transparent; font-style: normal;">Slides: <a href="https://speakerdeck.com/mrallen1/giving-lwp-its-well-deserved-golden-watch" class="" style="">https://speakerdeck.com/mrallen1/giving-lwp-its-well-deserved-golden-watch</a></div><div class="" style=""><br class="" style=""></div><div class="" style="">I have also used it to compare serialization library performance (specifically benchmarking pure-perl JSON encoding/decoding to XS based JSON encoding/decoding.)</div><div class="" style=""><br class="" style=""></div><div class="" style="">Mark</div> <div
 class="qtdSeparateBR"><br><br></div><div class="yahoo_quoted" style="display: block;"> <div style="font-family: lucida console, sans-serif; font-size: 13px;" class=""> <div style="font-family: HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif; font-size: 16px;" class=""> <div dir="ltr" class="" style=""> <font size="2" face="Arial" class="" style=""> On Monday, October 13, 2014 10:43 AM, Robert Stone via Houston <houston@pm.org> wrote:<br class="" style=""> </font> </div>  <br class="" style=""><br class="" style=""> <div class="" style="">Greetings,<br class="" style=""><br class="" style="">This is a very fascinating example of making use of Benchmark to empirically discover the most efficient method of performing an operation.  Thank you for putting it together!<br class="" style=""><br class="" style="">This is the first time I've seen Benchmark used (<a href="https://metacpan.org/pod/Benchmark" target="_blank"
 class="" style="">https://metacpan.org/pod/Benchmark</a>) and I think it's very powerful stuff.  A few questions come to mind for the list...<br class="" style=""><br class="" style="">1. Who wants to do a presentation on Benchmark? :)<br class="" style="">2. Who wants to do a presentation on Devel::NYTProf? :) :)<br class="" style=""><br class="" style="">In all seriousness though, this looks great.  Thanks again for taking the time to point out that while push/shift is a workable solution, I can squeak out a few more cycles with bit shifting.  Moreover, the bit shifting solution is likely what I will use in the XS version of the module.<br class="" style=""><br class="" style="">Best Regards,<br class="" style="">Robert Stone<br class="" style=""><br class="" style="">----- Original Message -----<br class="" style="">From: "G. Wade Johnson via Houston" <<a ymailto="mailto:houston@pm.org" href="mailto:houston@pm.org" class=""
 style="">houston@pm.org</a>><br class="" style="">To: "Houston Perl Mongers" <<a ymailto="mailto:houston@pm.org" href="mailto:houston@pm.org" class="" style="">houston@pm.org</a>><br class="" style="">Sent: Friday, October 10, 2014 10:37:18 PM<br class="" style="">Subject: [pm-h] Performance discussion after the meeting.<br class="" style=""><br class="" style="">After the meeting last night, I decided to do some investigation of the<br class="" style="">discussion we had about the word rotation code. I used Benchmark to get<br class="" style="">a rough idea of the speed of the different approaches we talked about.<br class="" style=""><br class="" style="">The four approaches I tested were:<br class="" style="">  push    - Robert's original approach<br class="" style="">  reanon  - recreate anonymous array each time to save memory creep<br class="" style="">  slice   - this was the array slice assignment we
 looked at last<br class="" style="">  twiddle - bit twiddling of the integer as we suggested for C<br class="" style=""><br class="" style="">Each test runs the actual code 10_000 times so that the subroutine<br class="" style="">overhead does not swamp the actual work. The loop overhead is probably<br class="" style="">not much of an issue.<br class="" style=""><br class="" style="">The program is between the lines:<br class="" style="">----------------------------------------------------------<br class="" style="">use strict;<br class="" style="">use warnings;<br class="" style="">use 5.010;<br class="" style=""><br class="" style="">use Benchmark qw/cmpthese/;<br class="" style="">use Devel::Size qw/total_size/;<br class="" style=""><br class="" style="">my @word = ("\x12", "\x34", "\x56", "\x78");<br class="" style="">my $int_word = 0x12345678;<br class="" style="">my $iters = 10_000;<br class="" style=""><br class="" style="">my %sizes;<br
 class="" style=""><br class="" style="">print "Orig size: ", total_size( \@word ), "\n";<br class="" style=""><br class="" style="">cmpthese( -2,<br class="" style="">    {<br class="" style="">        slice  => sub {<br class="" style="">            my $w = [ @word ];<br class="" style="">            foreach ( 0 .. $iters ) {<br class="" style="">                @{$w}[0..3] = @{$w}[1,2,3,0];<br class="" style="">            };<br class="" style="">            $sizes{slice} = total_size( $w );<br class="" style="">        }, <br class="" style="">        push   => sub {<br class="" style="">            my $w = [ @word ];<br class="" style="">           
 foreach ( 0 .. $iters ) {<br class="" style="">                push @{$w}, shift @{$w};<br class="" style="">            };<br class="" style="">            $sizes{push} = total_size( $w );<br class="" style="">        }, <br class="" style="">        reanon => sub {<br class="" style="">            my $w = [ @word ];<br class="" style="">            foreach ( 0 .. $iters ) {<br class="" style="">                $w = [ @{$w}[1,2,3,0] ];<br class="" style="">            };<br class="" style="">            $sizes{reanon} = total_size( $w );<br class="" style="">        }, <br class="" style="">        twiddle => sub
 {<br class="" style="">            my $w = $int_word;<br class="" style="">            foreach ( 0 .. $iters ) {<br class="" style="">                $w = ($w >> 1 | $w << 3);<br class="" style="">            }<br class="" style="">        }, <br class="" style="">    }<br class="" style="">);<br class="" style=""><br class="" style="">foreach my $t ( sort keys %sizes )<br class="" style="">{<br class="" style="">    print "$t: $sizes{$t}\n"; <br class="" style="">}<br class="" style="">----------------------------------------------------------<br class="" style=""><br class="" style="">The output is below:<br class="" style="">Orig size: 320<br class="" style="">         Rate   slice  reanon    push twiddle<br class=""
 style="">slice   127/s      --    -14%    -77%    -83%<br class="" style="">reanon  148/s     17%      --    -74%    -81%<br class="" style="">push    560/s    341%    278%      --    -27%<br class="" style="">twiddle 763/s    501%    415%     36%      --<br class="" style="">push: 400<br class="" style="">reanon: 320<br class="" style="">slice: 320<br class="" style="">-----------------------------------------------------------<br class="" style=""><br class="" style="">As you can see, Robert's solution (push) is about three times as fast<br class="" style="">as either of the other two. (It was 5-6 times as fast on another<br class="" style="">machine.) The memory issue I brought up has apparently been corrected.<br class="" style="">Although the array
 does grow in size, it's only 80 bytes, so that would<br class="" style="">not be a real issue.<br class="" style=""><br class="" style="">Interestingly, the bit twiddling response is only another 36% faster in<br class="" style="">Perl. Some of that is due to other changes in the sub. In C, I suspect<br class="" style="">it would be a whole lot faster.<br class="" style=""><br class="" style="">So, it looks like Robert had the best solution after all.<br class="" style=""><br class="" style="">G. Wade<br class="" style="">-- <br class="" style="">An expert is a person who has made all the mistakes that can be made in<br class="" style="">a very narrow field.                                    -- Niels Bohr<br class="" style="">_______________________________________________<br class="" style="">Houston mailing list<br class="" style=""><a
 ymailto="mailto:Houston@pm.org" href="mailto:Houston@pm.org" class="" style="">Houston@pm.org</a><br class="" style=""><a href="http://mail.pm.org/mailman/listinfo/houston" target="_blank" class="" style="">http://mail.pm.org/mailman/listinfo/houston</a><br class="" style="">Website: <a href="http://houston.pm.org/" target="_blank" class="" style="">http://houston.pm.org/</a><br class="" style="">_______________________________________________<br class="" style="">Houston mailing list<br class="" style=""><a ymailto="mailto:Houston@pm.org" href="mailto:Houston@pm.org" class="" style="">Houston@pm.org</a><br class="" style=""><a href="http://mail.pm.org/mailman/listinfo/houston" target="_blank" class="" style="">http://mail.pm.org/mailman/listinfo/houston</a><br class="" style="">Website: <a href="http://houston.pm.org/" target="_blank" class="" style="">http://houston.pm.org/</a><br class="" style=""><br class="" style=""><br class="" style=""></div> 
 </div> </div>  </div> </div></body></html>