in reply to unpacking 6-bit values

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

Replies are listed 'Best First'.
Re^2: unpacking 6-bit values
by BrowserUk (Patriarch) on Dec 11, 2010 at 09:40 UTC

    I haven't tested this as I can't get GMP to install here. I looked for a PPM for 64-bit 5.10 but none is available.

    I guess that you probably have made this available for 5.12 64-bit via your repo, but I don't see enough value in 5.12 to cause me to go through the pain of re-installing everything I have, to warrant my upgrading.

    Personally, I think the transition from 5.10 to 5.12 happened much to quickly. Maybe once 5.14 comes around.


    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.
      I looked for a PPM for 64-bit 5.10 but none is available

      Yes, the first perl that built with MinGW64 straight out of the box was 5.12 - so, since I'm using the MinGW64 compiler, I've currently limited myself to building only for 5.12 (as regards x64). When 5.14 is released I'll cover it for both x86 and x64, too ... so you might be able to catch up then :-)

      I can build these ppm's for x64 5.10 and 5.8 (I think) - and would happily do so for anyone that needs them, but by the time the x64 builds of ActivePerl become prevalent I expect that 5.10 and 5.8 will have long been superseded. I therefore don't currently intend to build and upload ppm's for these earlier x64 builds.

      I've thought about uploading the libraries themselves. But even if they were available, you'd have to grab the MinGW64 compiler (and make some modifications to a couple of your ActivePerl .pm files) before you'd be able to run the Inline::C script I posted. (When I switch to Math::GMPz, there's about a 6x slowdown - mainly, I think, because perl's for loops are much slower than C's.)
      Besides, it looks to me that you already have far better solutions ;-)

      I think the transition from 5.10 to 5.12 happened much to quickly

      It was certainly pretty quick - and 5.14 is due out next month !!

      Cheers,
      Rob