P is for Practical PerlMonks

### 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

++ 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).'}';
}

Create A New User
Node Status?
node history
Node Type: note [id://1021347]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (8)
As of 2017-06-25 08:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
How many monitors do you use while coding?

Results (565 votes). Check out past polls.