joe_b has asked for the wisdom of the Perl Monks concerning the following question:
I'm looking for a faster way to de-interleave binary data. I have some source files (~200MB in size) of interleaved data that contain two data streams. The data is interleaved one bit at a time (e.g., if stream one is all 1's and stream two is all 0's, the file would read as "1010101010101010....", and I would like the resultant files to read "1111111..." and "000000...").
The code below works, but is slow (so it seems to me - it takes about 40 minutes to de-interleave a 192MB file on a modern laptop). I read in some data, split each bit into an array, the split that array into two sub arrays, then write it back out. I'm a newbie to Perl and programming in general, which may be obvious from my code.
I've tried reading in bigger chunks of data, but it doesn't help. It seems it's all the unpacking and array operations that take the most time. Thanks.until ($filesize <= $offset) { sysseek (INTERLEAVED_DATA, $offset, 0); sysread (INTERLEAVED_DATA, $buffer, 8192); @interleaved = split(//, unpack("b*", $buffer)); $buffer = ""; while (@interleaved){ push @uninterleaved_1, shift @interleaved; push @uninterleaved_2, shift @interleaved; } $uninterleaved_1 = pack "b*", join "", @uninterleaved_1; @uninterleaved_1 = ""; $uninterleaved_2 = pack "b*", join "", @uninterleaved_2; @uninterleaved_2 = ""; syswrite (UNINTERLEAVED_1, $uninterleaved_1); syswrite (UNINTERLEAVED_2, $uninterleaved_2); $uninterleaved_1 = ""; $uninterleaved_2 = ""; $offset = $offset + 8192; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: de-interleaving binary data
by Roy Johnson (Monsignor) on Jun 27, 2007 at 21:49 UTC | |
|
Re: de-interleaving binary data
by BrowserUk (Patriarch) on Jun 28, 2007 at 00:49 UTC | |
by joe_b (Initiate) on Jun 28, 2007 at 14:32 UTC | |
by BrowserUk (Patriarch) on Jun 28, 2007 at 15:36 UTC | |
|
Re: de-interleaving binary data
by merlyn (Sage) on Jun 27, 2007 at 20:39 UTC |