in reply to Re^5: Shortcutting grep in boolean context
in thread Shortcutting grep in boolean context

I was not aware of List::MoreUtils::firstval. Okay, added it to the benchmark. It mostly has the same speed as List::Util::first, I wonder what the differences are.

% bencher -Ilib -m PERLANCAR/grep_bool --include-participant-pattern List::
+---------------------------+----------+-----------+-----------+------------+---------+---------+
| participant               | dataset  | rate (/s) | time (μs) | vs_slowest |  errors | samples |
+---------------------------+----------+-----------+-----------+------------+---------+---------+
| List::Util::first         | notfound |      3900 |   250     |      1     | 1.8e-06 |      20 |
| List::MoreUtils::firstval | last     |      3980 |   251     |      1.01  | 5.3e-08 |      20 |
| List::MoreUtils::firstval | notfound |      4000 |   250     |      1     | 1.1e-06 |      20 |
| List::Util::first         | last     |      4100 |   240     |      1     | 4.8e-07 |      20 |
| List::Util::first         | first    |     46400 |    21.6   |     11.8   | 2.1e-08 |      31 |
| List::MoreUtils::firstval | first    |     46406 |    21.549 |     11.788 | 1.5e-10 |      20 |
+---------------------------+----------+-----------+-----------+------------+---------+---------+
  • Comment on Re^6: Shortcutting grep in boolean context

Replies are listed 'Best First'.
Re^7: Shortcutting grep in boolean context
by LanX (Saint) on Jan 04, 2017 at 01:54 UTC
    > I wonder what the differences are.

    I wouldn't be surprised if it's the same code.

    IIRC (?) were these features first introduced in List::MoreUtils and later in List::Util .

    Thanks for the benchmark, have to look closer into it.

    It's very surprising that the XS code may be so inefficient.

    Cheers Rolf
    (addicted to the Perl Programming Language and ☆☆☆☆ :)
    Je suis Charlie!