File: permutations.pl

package info (click to toggle)
libalgorithm-combinatorics-perl 0.27-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 212 kB
  • sloc: perl: 399; makefile: 2
file content (27 lines) | stat: -rw-r--r-- 477 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
use strict;
use warnings;

use Algorithm::Combinatorics qw(permutations);
use Math::Combinatorics;
use Benchmark qw(cmpthese);

our @data = 1..7;

sub aperm {
   my $iter = permutations(\@data);
   1 while $iter->next;
}

sub mperm {
    my $iter = Math::Combinatorics->new(data => \@data);
    1 while $iter->next_permutation;
}

cmpthese(-10, {
    aperm => \&aperm,
    mperm => \&mperm,
});

#         Rate mperm aperm
# mperm 12.2/s    --  -78%
# aperm 54.4/s  347%    --