in reply to Re^2: Where does the spurious error message come from?
in thread Where does the spurious error message come from?

How does it compare speed-wise with List::Util::any? I've always found that fast enough for my needs but maybe I'm just not very demanding.


🦛

  • Comment on Re^3: Where does the spurious error message come from?

Replies are listed 'Best First'.
Re^4: Where does the spurious error message come from?
by kcott (Archbishop) on Aug 06, 2023 at 00:32 UTC
    "How does it compare speed-wise ..."

    A very quick benchmark shows no appreciable difference.

    #!/usr/bin/env perl use strict; use warnings; use Array::Contains; use List::Util 'any'; use Benchmark 'cmpthese'; my @base = 'A' .. 'Z'; my @search = map +($_, lc), @base; print "\@base[@base]\n"; print "\@search[@search]\n"; cmpthese 0 => { lua => \&lua, acc => \&acc, }; sub lua { for my $x (@search) { my $bool = any { $_ eq $x } @base; } return; } sub acc { for my $x (@search) { my $bool = contains($x, \@base); } return; }

    The check on the arrays was the same on each run:

    @base[A B C ... X Y Z] @search[A a B b C c ... X x Y y Z z]

    Here's the results of three runs:

    Rate lua acc lua 15544/s -- -1% acc 15622/s 1% -- Rate acc lua acc 15777/s -- -1% lua 15905/s 1% -- Rate acc lua acc 15782/s -- -0% lua 15857/s 0% --

    — Ken

      Interesting. With perl 5.26.1 and List::Util 1.4602, I'm getting
      Rate acc lua acc 6474/s -- -48% lua 12361/s 91% --
      and even more if I use a longer list
      my @base = ('A' .. 'Z') x 100;

      map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

        G'day choroba,

        ++ Thanks for checking it out.

        The results I originally posted were from: Perl 5.38.0; List::Util 1.63; and, Array::Contains 2.8.

        I reran the benchmark with the earliest Perl I have to hand: Perl 5.30.0; List::Util 1.5; and, Array::Contains 2.8.

        Rate lua acc lua 14610/s -- -4% acc 15247/s 4% -- Rate lua acc lua 14826/s -- -2% acc 15103/s 2% -- Rate lua acc lua 14821/s -- -3% acc 15318/s 3% --

        Those numbers are very close and I'd still consider this to indicate no appreciable difference.

        I ran both on:

        $ uname -a CYGWIN_NT-10.0-19045 titan 3.4.7-1.x86_64 2023-06-16 14:04 UTC x86_64 +Cygwin

        which has the latest 3.4.7 update which I did about two days ago.

        Addendum: I just checked those Perl versions with List::Util::XS: XS version installed on both.

        — Ken