Sorry using string benchmarks didn't combine well with lexical globals in my last benchmark.
Your benchmark with ano-subs shows LMU being 3 times as fast for arrays of length 1000.
use strict; use warnings; use Benchmark qw(cmpthese); use Data::Dump qw/pp/; #use List::Util 1.35 (); BEGIN { *any_lu = *List::Util::any }; use List::MoreUtils (); BEGIN { *any_lmu = *List::MoreUtils::any }; sub any_pp (&@) { my $code = shift; map {&$code and return 1} @_ ; () +} my (@LIST,$TARGET); our (@LIST2,$TARGET2); { no warnings 'once'; @LIST2 = @LIST = (0..1000); $TARGET2 = $TARGET = $LIST[@LIST/2]; } local $,="\t"; my $suite= { any_lmu => sub { any_lmu { $_ eq $TARGET } @LIST }, any_pp => sub { any_pp { $_ eq $TARGET } @LIST }, }; pp $suite; cmpthese(-1,$suite); __END__ { any_lmu => sub { "???" }, any_pp => sub { "???" } } Rate any_pp any_lmu any_pp 1027/s -- -66% any_lmu 3027/s 195% --
In reply to Re^10: Smartmatch alternatives
by LanX
in thread Smartmatch alternatives
by cavac
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |