Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^4: Parsing Motorola S-Rec file

by Tux (Canon)
on Sep 03, 2014 at 13:46 UTC ( [id://1099408]=note: print w/replies, xml ) Need Help??


in reply to Re^3: Parsing Motorola S-Rec file
in thread Parsing Motorola S-Rec file

Why not take the last step too?

$ cat test.pl use 5.16.2; use warnings; use Benchmark qw( cmpthese ); use List::Util qw( reduce sum ); my $count = 12; my $address = "A42187B56F"; my $data = "39AD0D96D51CD3"; my $r = sub { reduce { $a + $b } map { hex $_ } ($count, $address =~ m/../g, $data =~ m/../g); }; my $s = sub { sum map { hex } $count, (unpack "(A2)*", $address), (unpack "(A2)*", $data); }; say $r->(); say $s->(); cmpthese (-2, { LUreduce => $r, LUsum => $s }); $ perl test.pl 1487 1487 Rate LUreduce LUsum LUreduce 216392/s -- -40% LUsum 359162/s 66% --

Enjoy, Have FUN! H.Merijn

Replies are listed 'Best First'.
Re^5: Parsing Motorola S-Rec file
by AppleFritter (Vicar) on Sep 03, 2014 at 16:57 UTC
    Ah, good point! I'm so used to using reduce for everything that sum didn't even occur to me. (And I've never been as comfortable with (un)pack as with regular expressions; time to remedy that, perhaps.)
Re^5: Parsing Motorola S-Rec file
by gri6507 (Deacon) on Sep 03, 2014 at 14:25 UTC
    I'm sorry, but my Perl understanding is not quite up to par to understand what's going on here, or why this is better. Can you please clarify?

      Using sum plus unpack "(A2)*" is 66% faster than using reduce plus m/../g.


      Enjoy, Have FUN! H.Merijn

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (5)
As of 2024-04-23 21:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found