File: subsets.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 (31 lines) | stat: -rw-r--r-- 733 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
29
30
31
use strict;

use Algorithm::Combinatorics qw(subsets);
use List::PowerSet;
use Benchmark qw(cmpthese);

our @data = 1..10;

sub lps_subsets {
    my $p = List::PowerSet::powerset_lazy(@data);
    1 while $p->();
}

sub ac_subsets {
    my $p = subsets(\@data);
    1 while $p->next;
}


cmpthese(-15, {
    lps_subsets => \&lps_subsets,
    ac_subsets  => \&ac_subsets,
});

# The iterator is faster, but the subroutine that gives the entire powerset
# in List::PowerSet is faster than our code in list context. We do not provide
# that one because one of the premises of this module is to not recurse.

#             Rate lps_subsets  ac_subsets
#lps_subsets 120/s          --        -50%
#ac_subsets  241/s        101%          --