Bit-Set
view release on metacpan or search on metacpan
lib/Bit/Set/OO.pm view on Meta::CPAN
use base 'sealed';
use sealed 'deparse';
use Bit::Set ':all';
use Bit::Set::OO;
use constant SIZE_OF_TEST_BIT => 65536;
use constant SIZEOF_BITDB => 45;
cmpthese 20_000_000, {
bsoo => sub {
my $b = Bit::Set->new(SIZE_OF_TEST_BIT);
$b->bset(2);
$b->put(3, 1);
die unless $b->get(2) == 1;
die unless $b->get(3) == 1;
undef $b;
},
sealed => sub :Sealed {
my Bit::Set $b;
$b = $b->new(SIZE_OF_TEST_BIT);
$b->bset(2);
$b->put(3, 1);
die unless $b->get(2) == 1;
die unless $b->get(3) == 1;
undef $b;
},
bs => sub {
my $b = Bit_new(SIZE_OF_TEST_BIT);
Bit_bset($b,2);
Bit_put($b,3,1);
die unless Bit_get($b, 2) == 1;
die unless Bit_get($b, 3) == 1;
Bit_free(\$b);
}
};
ok(1);
B<Background on Performant Object Oriented interfaces>
Joe Scahefer's L<sealed|https://metacpan.org/pod/sealed> in combination with XS provide unique opportunities to improve the peformance of OO interfaces without the overhead of traditional Perl OO systems by "sealing" the methods at compile time. As ...
"Perl 5s OO runtime method lookup has 50% more performance overhead than a
direct, named subroutine invocation."
Doug MacEachern proposed a very L<solution|https://www.perl.com/pub/2000/06/dougpatch.html/> which however never made it into the core.
Joe's sealed package implements Doug's idea in a modern way, allowing the
creation of efficient OO interfaces without the overhead of traditional Perl OO
systems by "sealing" the methods at compile time. In order for these methods to shine, the right combination of ingredients is needed:
=over 4
=item 1 The overhead of the dynamic lookup should be significant compared to the work done in the method itself.
This is the case for small methods that do little work, such as getters and setters. However, this is also the case when the underlying C function is very fast, as is the case with the Bit library.
=item 2 The XS interface should materially decrease the overhead of the method call itself.
This is really a corollary of point 1 above, but it is worth stating explicitly.
=item 3 The methods should be used to process large numbers of objects in tight loops.
This is where the overhead of dynamic method lookup really adds up, and where the benefits of XS and sealing the methods at compile time become apparent.
=back
=head1 SEE ALSO
=over 4
=item L<Alien::Bit|https://metacpan.org/pod/Alien::Bit>
This distribution provides the library Bit so that it can be used by other Perl
distributions that are on CPAN. It will download Bit from Github and will build
the (static and dynamic) versions of the library for use by other Perl modules.
=item L<benchmarking-bits|https://github.com/chrisarg/benchmarking-bits>
A collection of benchmarking scripts for various bitset libraries in C and Perl.
=item L<Bit|https://github.com/chrisarg/Bit>
Bit is a high-performance, uncompressed bitset implementation in C, optimized
for modern architectures. The library provides an efficient way to create,
manipulate, and query bitsets with a focus on performance and memory alignment.
The API and the interface is largely based on David Hanson's Bit_T library
discussed in Chapter 13 of "C Interfaces and Implementations",
Addison-Wesley ISBN 0-201-49841-3 extended to incorporate additional operations
(such as counts on unions/differences/intersections of sets),
fast population counts using the libpocnt library and GPU operations for packed
containers of (collections) of Bit(sets).
=item L<Bit::Set|https://metacpan.org/pod/Bit::Set>
C<Bit::Set> is a Perl module that provides a high-level I<procedural> interface
for working with bitsets. It is built on top of the Bit library and offers a
more user-friendly Perl API for common bitset operations.
=item L<Bit::Set::DB|https://metacpan.org/pod/Bit::Set::DB>
Procedural interface to the containerized operations of the Bit library.
=item L<Bit::Set::DB::OO|https://metacpan.org/pod/Bit::Set::DB::OO>
Object Oriented interface to the Bit::Set::DB module.
=item L<Bit::Vector|https://metacpan.org/pod/Bit::Vector>
Efficient bit vector, set of integers and "big int" math library
=item L<Lucy::Object::BitVector|https://metacpan.org/dist/Lucy/view/lib/Lucy/Object/BitVector.pod>
Bit vector implementation used in the L<Lucy|https://metacpan.org/pod/Lucy> search engine library.
=item L<sealed|https://metacpan.org/pod/sealed>
Subroutine attribute for compile-time method lookups on its typed lexicals.
( run in 1.833 second using v1.01-cache-2.11-cpan-e1769b4cff6 )