File: combinations.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 (28 lines) | stat: -rw-r--r-- 507 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
28
use strict;
use warnings;

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

our @data = 1..10;
our $n = 7;

sub acomb {
   my $iter = combinations(\@data, $n);
   1 while $iter->next;
}

sub mcomb {
    my $iter = Math::Combinatorics->new(count => $n, data => \@data);
    1 while $iter->next_combination;
}

cmpthese(-10, {
    acomb => \&acomb,
    mcomb => \&mcomb,
});

#         Rate mcomb acomb
# mcomb 87.7/s    --  -96%
# acomb 2245/s 2461%    --