Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • Can you test how good would perform List::Util::first()?

    • Well, you won't like it... Using the code:

      first => sub { my $x = defined first { $_ eq $search } @letters },

      first is always close to 20% slower than any...

      Search for Z
                Rate    Time first  any
      first  38653/s 25.87us    -- -21%
      any    48955/s 20.43us   27%   --

      Search for M
                Rate    Time first  any
      first  49484/s 20.21us    -- -22%
      any    63620/s 15.72us   29%   --

      Search for C
                Rate    Time first  any
      first  67151/s 14.89us    -- -18%
      any    81812/s 12.22us   22%   --

      Search for A
                Rate    Time first  any
      first  73125/s 13.68us    -- -21%
      any    92772/s 10.78us   27%   --

      Search for banana
                Rate    Time first  any
      first  40513/s 24.68us    -- -19%
      any    50019/s 19.99us   23%   --

      • Your observation seems to be only true for small arrays. In this plot [] you can see how first() gets better with larger arrays.

        In this benchmark [] grep and first were searching for the middle element in the array.