in reply to Re: unpacking 6-bit values
in thread unpacking 6-bit values

Update 3: I can't make pack & unpack work

Phew! I thought I was going nuts :)

From what I read, uuencode converts each 3-bytes to 4-bytes, which is the reverse of what I need.

Then I thought maybe I could use the decode process to perform my encoding, but I couldn't make that work either :(

But it sure did sound like a cool idea to start with.

Replies are listed 'Best First'.
Re^3: unpacking 6-bit values
by roboticus (Chancellor) on Dec 10, 2010 at 22:52 UTC

    BrowserUk:

    Yep. I saw it, and then looked at Wikipedia to check out what it was, and they had a nice little example there. I was hoping it was going to be fast, so I was putting it in a benchmark script, but I then discovered the bad news.

    The benchmark script (such as it is):

    The benchmark script shows a little bit of a speed boost, but not what I was hoping for. I may have to try Inline::C to see what we can get. Note: The benchmark isn't useful yet, as I haven't necessarily plugged your or jethros code in properly. If I had more time to put into it, I'd've added some of the other solutions as well. But I had to go to work, and now I've got to feed my son and do some chores.

    roboticus@Boink:~ $ perl 876421.pl REF: 14 21 16 1a 33 01 12 1a 33 01 22 1b 2f 11 07 08 21 01 02 1a 21 11 + 27 0b jethro: matches robo_2: matches Rate BrowserUk jethro robo_2 BrowserUk 11876/s -- -6% -20% jethro 12642/s 6% -- -15% robo_2 14837/s 25% 17% --

    Thanks for coming up with a fun diversion for this morning!

    ...roboticus

    When your only tool is a hammer, all problems look like your thumb.

      Thanks for coming up with a fun diversion for this morning!

      T'is fun isn't it ;) But, it will also serve a very practical purpose, which (for me) makes it all the more fun. It always amazes me the diversity of approaches that the monks come up with for tackling seemingly quite tightly defined problems like this. That's why I posted it; and one of the very best things about this community.

      See also Re: unpacking 6-bit values for my benchmark of 4 pure perl solutions and 3 C routines, including one of yours. I would have posted it earlier, but it took a considerable amount of effort to ensure that all the routines actually produced the same output. That meant adapting almost of the posted code to some degree or another.

      jmacnamara's solution is hands down winner in the pure perl stakes, being roughly twice as fast as my original. But the C versions, which are all much of a muchness, despite being radically different in the way they achieve the solutions, are a good 5 times faster still. Had there been a directly usable pack/unpack version, I would have expected a far smaller differential, perhaps small enough to warrant avoiding moving to C; but as is, I think C will be necessary for this.

      Thank you (and everyone) for your time and effort, it helped me a lot.


      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.