in reply to Re^8: Smartmatch alternatives
in thread Smartmatch alternatives
Really? In my benchmarks, the XS versions are significantly faster. The List::Util XS version is faster than List::MoreUtils too.
use strict; use warnings; use Benchmark qw(cmpthese); 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; &$code and return 1 for @_ ; () } { no warnings 'once'; @::LIST = (0..9); $::TARGET = 5; } cmpthese(-1, { any_lu => q[ any_lu { $_ eq $::TARGET } @::LIST ], any_lmu => q[ any_lmu { $_ eq $::TARGET } @::LIST ], any_pp => q[ any_pp { $_ eq $::TARGET } @::LIST ], }); __END__ Rate any_pp any_lmu any_lu any_pp 65761/s -- -79% -80% any_lmu 309688/s 371% -- -5% any_lu 324588/s 394% 5% --
For longer lists, the difference becomes more pronounced:
{ no warnings 'once'; @::LIST = (0..99); $::TARGET = 50; } ... __END__ Rate any_pp any_lmu any_lu any_pp 10195/s -- -84% -85% any_lmu 63999/s 528% -- -4% any_lu 66370/s 551% 4% --
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^10: Smartmatch alternatives
by LanX (Saint) on Dec 18, 2013 at 08:15 UTC |