Skip Menu |

This queue is for tickets about the Array-OneOf CPAN distribution.

Report information
The Basics
Id: 81384
Status: resolved
Priority: 0/
Queue: Array-OneOf

People
Owner: Nobody in particular
Requestors: perl [...] toby.ink
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: (no value)
Fixed in: (no value)



Subject: Quite slow
Array::OneOf performs quite poorly speed-wise compared to other solutions. A benchmark script is attached to this bug report comparing five different techniques for determining if an element is in an array. Array::OneOf is the slowest. Perl's built-in smart match operator is the fastest by far, about 14 times the speed on my machine. However, it may not always have the desired effect - for example "0000" matches "0".
Subject: any.pl
use v5.14; use Benchmark qw( :all ); use Test::More tests => 5; use Array::OneOf qw( oneof ); use List::MoreUtils qw( any ); use Syntax::Keyword::Junction any => { -as => 'j_any' }; my @array = 'a' .. 'z'; my %solutions = ( array_oneof => sub { oneof 'n', @array }, junction => sub { 'n' eq j_any(@array) }, grep => sub { grep { $_ eq 'n' } @array }, any => sub { any { $_ eq 'n' } @array }, smart_match => sub { 'n' ~~ @array }, ); for my $s (sort keys %solutions) { ok $solutions{$s}->(), "$s works"; } diag "Benchmarks (high numbers are fast)"; my $timings = timethese -1, \%solutions, 'none'; for my $s (sort keys %$timings) { diag sprintf("%-12s : %d", $s, $timings->{$s}[5]); }
Good feedback. In the POD for the new release I summarized what you said and provided the alternatives you gave in your feedback. I also explained that Array::OneOf meets my specific set of needs: string comparison, undef only equals undef, and small footprint. Array::OneOf is one of a set of home grown utilities I use in a larger open-source project I will be releasing. It is a minuscule part of the project. I just need it to be available on CPAN for when people install the system. Thanks Miko On Fri Nov 23 12:02:45 2012, TOBYINK wrote: Show quoted text
> Array::OneOf performs quite poorly speed-wise compared to other solutions. > > A benchmark script is attached to this bug report comparing five > different techniques for determining if an element is in an array. > > Array::OneOf is the slowest. > > Perl's built-in smart match operator is the fastest by far, about 14 > times the speed on my machine. However, it may not always have the > desired effect - for example "0000" matches "0".