Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

Re^2: Multiple Permutation handling

by rjt (Deacon)
on Mar 01, 2013 at 21:35 UTC ( #1021347=note: print w/replies, xml ) Need Help??

in reply to Re: Multiple Permutation handling
in thread Multiple Permutation handling

++ for clever use of glob. It actually performs quite well in this case:

Rate Algorithm::Loops glob Nested l +oops Algorithm::Loops 371/s -- -88% +-91% glob 3059/s 724% -- +-27% Nested loops 4219/s 1036% 38% + --
#!/usr/bin/env perl use warnings; use 5.014; use Algorithm::Loops qw/NestedLoops/; use Benchmark qw/:all/; my @SKU = (1..5); my @shirt = qw/T S L H/; my @size = qw/S M L XL 2X/; my @col = qw/BLU GRN WHT BLK/; say scalar algorithm_loops(); say scalar nested_loops(); say scalar do_glob(); cmpthese(-10, { 'Algorithm::Loops' => \&algorithm_loops, 'Nested loops' => \&nested_loops, 'glob' => \&do_glob, }); sub algorithm_loops { return NestedLoops([ \@SKU, \@shirt, \@size, \@col ], sub { 'SKU' . join '', @_ }); } sub nested_loops { my @r; for my $sku (@SKU) { for my $shirt (@shirt) { for my $size (@size) { for my $col (@col) { push @r, 'SKU'.$sku.$shirt.$size.$col; } } } } return @r; } sub do_glob { () = glob 'SKU{'.join(',',@SKU).'}{'. join(',',@shirt).'}{'. join(',',@size).'}{'. join(',',@col).'}'; }

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1021347]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (8)
As of 2018-05-23 10:08 GMT
Find Nodes?
    Voting Booth?