in reply to Why is "any" slow in this case?

In your any and any_cr branches you are running any twice when you only need to run it once. If I fold the two together like this:

any_fold => sub { while ( $data =~ /^(\d+) (\d+)/mg ) { next if any { $1 == $_ || $2 == $_ } @skip; } return 1 }, any_cr_fold => sub { while ( $data =~ /^(\d+) (\d+)/mg ) { my ( $c, $r ) = ( $1, $2 ); next if any { $c == $_ || $r == $_ } @skip; } return 1 },

I get these results:

any_cr 461/s -- -13% -58% -62% -68% + -76% any_cr_fold 527/s 14% -- -52% -57% -63% + -72% any 1090/s 137% 107% -- -11% -24% + -43% any_fold 1221/s 165% 132% 12% -- -15% + -36% ugly 1436/s 212% 172% 32% 18% -- + -25% ugly_cr 1914/s 315% 263% 76% 57% 33% + --

Then, since I am on 5.42.0 and can use the new any keyword (suggested by ysth) by replacing your use of List::Util with:

no warnings "experimental::keyword_any"; use experimental 'keyword_any';

it gives these even better results:

Rate any any_fold any_cr ugly any_cr_fold + ugly_cr any 1037/s -- -10% -20% -26% -31% + -46% any_fold 1152/s 11% -- -11% -18% -23% + -40% any_cr 1297/s 25% 13% -- -7% -14% + -32% ugly 1399/s 35% 21% 8% -- -7% + -27% any_cr_fold 1506/s 45% 31% 16% 8% -- + -21% ugly_cr 1914/s 85% 66% 48% 37% 27% + --

ugly_cr still wins but not by so much. But what's really interesting to me is that with List::Util, any_cr is much slower than any while with the new keyword, any_cr is slightly faster than any.


🦛