Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Perlish approach to parsing a binary blob

by vr (Curate)
on Apr 09, 2018 at 17:38 UTC ( #1212605=note: print w/replies, xml ) Need Help??


in reply to Perlish approach to parsing a binary blob

If "L" in "blob" stands for "large", and script is anything but a throw-away one-liner, I'd be unhappy about implicitly building large useless intermediate lists.

use strict; use warnings; use feature 'say'; use Data::Dump 'dd'; use Benchmark 'cmpthese'; my $data = "1ABCD2EFGH3IJKL4MNOP5QRST6UVWX" x 1000; cmpthese -3, { 1 => sub { my @out; for ( my $x = 0; $x < length $data; $x += 5 ) { push @out, [ unpack "CA4", substr $data, $x, 5 ] } return \@out }, 2 => sub { [ map [ unpack 'CA4', $_ ], unpack "(A5)*", $data ] } }; __END__ Rate 2 1 2 34.2/s -- -21% 1 43.1/s 26% --

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1212605]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (4)
As of 2020-09-29 22:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    If at first I donít succeed, I Ö










    Results (153 votes). Check out past polls.

    Notices?