*COMPLETELY UPDATED, FORGET WHAT I WROTE BEFORE IN THIS POST*

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.