I'd try to make use of the gmp library ... but in all honesty I have absolutely no idea how sane that is.
The following takes about 3 seconds to process 100,000 such numbers as described. (It does, of course, take longer to create the 100,000 bitstrings in the first place, and would also take longer if it were to output the results of its processing.

It could, no doubt, be improved upon ... but if it's not already "in the ballpark", then it's probably not worth persevering with.

It could also be taken out of the realm of Inline::C and into the realm of Math::GMPz - suffering only minimal losses.
Since we're dealing with such small bitstrings, I would not be at all surprised if this is *not* such a smart approach.
use warnings; use strict; use Inline C => Config => INC => '-IC:/_32/msys/1.0/local/include', LIBS => '-LC:/_32/msys/1.0/local/lib -lgmp', BUILD_NOISY => 1, USING => 'ParseRegExp'; use Inline C => <<'EOC'; #include <gmp.h> void process(SV * inp) { Inline_Stack_Vars; mpz_t in, ret, and; int i; mpz_init2(in, 192); mpz_set_str(in, SvPV_nolen(inp), 2); mpz_init_set_ui(and, 63); mpz_init2(ret, 6); Inline_Stack_Reset; for(i=0; i<32; i++) { mpz_and(ret, in, and); Inline_Stack_Push(newSVuv(mpz_get_ui(ret))); mpz_div_2exp(in, in, 6); } Inline_Stack_Done; Inline_Stack_Return(32); } EOC my @in; my @result; for(1..100000) { push @in, create(); } print time, "\n"; for(@in) { @result = process($_); } print time, "\n"; print "$in[-1]\n@result\n"; sub create { my $ret; $ret .= int(rand(2)) for 0..191; return $ret; }
Cheers,
Rob

In reply to Re: unpacking 6-bit values by syphilis
in thread unpacking 6-bit values by BrowserUk

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.