any can be found in List::MoreUtils.

I was bored a while ago, and plugged both any and grep into ikegamis benchmark script. They're slow.

use List::MoreUtils qw( any ); my $test_any = q{ my $rv = any { $var eq $_ } qw/ A B C /; }; my $test_grep = q{ my $rv = grep { $var eq $_ } qw/ A B C /; };
Compilation tests any: Compiles ok grep: Compiles ok if: Compiles ok ihash: Compiles ok re: Compiles ok shash: Compiles ok Benchmarking no matches any: Runs ok grep: Runs ok if: Runs ok ihash: Runs ok re: Runs ok shash: Runs ok Rate any ihash grep re if shash any 150377/s -- -77% -87% -91% -93% -96% ihash 649176/s 332% -- -44% -63% -69% -84% grep 1161774/s 673% 79% -- -33% -44% -71% re 1731140/s 1051% 167% 49% -- -17% -57% if 2085235/s 1287% 221% 79% 20% -- -49% shash 4071762/s 2608% 527% 250% 135% 95% -- Benchmarking match A any: Runs ok grep: Runs ok if: Runs ok ihash: Runs ok re: Runs ok shash: Runs ok Rate any ihash grep re shash if any 148303/s -- -75% -86% -94% -96% -96% ihash 595781/s 302% -- -45% -76% -85% -85% grep 1087949/s 634% 83% -- -55% -72% -73% re 2440645/s 1546% 310% 124% -- -37% -39% shash 3872575/s 2511% 550% 256% 59% -- -3% if 3994937/s 2594% 571% 267% 64% 3% -- Benchmarking match B any: Runs ok grep: Runs ok if: Runs ok ihash: Runs ok re: Runs ok shash: Runs ok Rate any ihash grep re if shash any 150377/s -- -75% -87% -92% -94% -96% ihash 603620/s 301% -- -47% -69% -78% -85% grep 1147836/s 663% 90% -- -40% -58% -71% re 1924833/s 1180% 219% 68% -- -29% -52% if 2725258/s 1712% 351% 137% 42% -- -32% shash 4014817/s 2570% 565% 250% 109% 47% -- Benchmarking match C any: Runs ok grep: Runs ok if: Runs ok ihash: Runs ok re: Runs ok shash: Runs ok Rate any ihash grep re if shash any 138400/s -- -78% -88% -93% -94% -96% ihash 634042/s 358% -- -47% -68% -71% -83% grep 1193008/s 762% 88% -- -40% -45% -68% re 1994574/s 1341% 215% 67% -- -8% -46% if 2157141/s 1459% 240% 81% 8% -- -42% shash 3709584/s 2580% 485% 211% 86% 72% --

In reply to Re^3: Collapsing repetitive equality tests: || vs {} vs // (an observation) by rhesa
in thread Collapsing repetitive equality tests: || vs {} vs // (an observation) by blogical

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.