Welcome to the Monastery | |
PerlMonks |
Re: Can unpack add zero bytes before converting?by mossi2000 (Initiate) |
on Sep 13, 2021 at 13:19 UTC ( [id://11136717]=note: print w/replies, xml ) | Need Help?? |
Hi to all who have answered! Thanks for all your input. Of course my question was driven by "need for speed". I tried to minimize the number of loops to go over the buffer (2k, 4k, 8k, or 16k of values) I extended the benchmark script and put the different solutions all in there. Below you can see the results. Three things: -I was astonished that the unpack_pack_unpack way is still twice as fast as my solution using bitstrings. -the solution with the borrowed pad to 8 bytes is really nifty! With one single buffer padding, one can nearly achieve what I wanted first. One unpack only. -Next surprise: the used $_ &= $mask for @values; does the same as map { $_ &= $mask) @values; but is about 25% faster....Must be the useless generation of the resulting array... (the test with @values = map { $_ &= $mask) @values; gets a rate of only 4000/s!!) So of course I'll go with the fastest solution, which has the advantage that it includes the easy case of 8 bytes per value at no cost when I pre-compute the unpack format. Thanks again, Axel
In Section
Seekers of Perl Wisdom
|
|