Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

This is what I mean by "not really extensible":

#! perl -slw use strict; use Benchmark qw[ cmpthese ]; our $I //= -1; our $N //= 4; my @ls = map int( 2+rand 10 ), 1 .. $N; our $str = pack 'S*', @ls; $str .= 'x' x ($_-1) . ' ' for @ls; cmpthese $I, { a => q[ # line 1 "a" my $templ = "S$N" . join( ' ', map{ "\@0 x[S$_] S \@0" . "S$_ x[S${ \( $N-$_ )}]" . '/x' x $_ . '/a' } 0 .. $N-1 ); my( @d ) = unpack $templ, $str; shift @d for 1 .. $N; $I == 1 and print 'a ', join '|', @d; ], b => q[ # line 1 "b" my @l = unpack "S$N", $str; my $templ = "x[S$N]" . join( ' a', '', @l ); my @d = unpack $templ, $str; $I == 1 and print 'b ', join '|', @d; ], }; __END__ C:\test>junk -I=-1 -N=1 Rate a b a 128551/s -- -59% b 312873/s 143% -- C:\test>junk -I=-1 -N=10 Rate a b a 19086/s -- -67% b 57153/s 199% -- C:\test>junk -I=-1 -N=100 Rate a b a 894/s -- -89% b 7979/s 793% --

You can clean that up by not returning the counts -- which are redundant -- but it is still doing a shit load of extra work in order to avoid two calls to unpack.


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

In reply to Re^5: how to unpack a C struct with length array preceding data array by BrowserUk
in thread how to unpack a C struct with length array preceding data array by johnlumby

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!
  • 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, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            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.
  • Log In?
    Username:
    Password:

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

    How do I use this? | Other CB clients
    Other Users?
    Others musing on the Monastery: (14)
    As of 2014-07-25 13:02 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      My favorite superfluous repetitious redundant duplicative phrase is:









      Results (171 votes), past polls