Files
lo/benchmark
d-enk d0901349e7 perf: optimize it.ContainsBy, EveryBy, SomeBy, NoneBy to avoid unnecessary allocations (#812)
Replace intermediate iterator chains with direct loops and early returns.

The direct loops with early return eliminate intermediate iterator
creation from Filter(), Reject(), IsNotEmpty() and IsEmpty() functions.

Benchmark results (benchstat):
                         │    old.txt    │               new.txt               │
                         │    sec/op     │    sec/op     vs base               │
ItContainsBy/ints_10-4      807.2n ± 54%   151.0n ±  6%  -81.29% (p=0.000 n=8)
ItContainsBy/ints_100-4     2.447µ ± 14%   1.531µ ± 11%  -37.42% (p=0.000 n=8)
ItContainsBy/ints_1000-4    17.67µ ±  4%   13.85µ ±  4%  -21.64% (p=0.000 n=8)
ItEveryBy/ints_10-4        1022.5n ± 63%   208.0n ± 34%  -79.66% (p=0.000 n=8)
ItEveryBy/ints_100-4        5.640µ ± 36%   1.542µ ±  9%  -72.67% (p=0.000 n=8)
ItEveryBy/ints_1000-4       52.22µ ± 54%   19.29µ ± 16%  -63.06% (p=0.000 n=8)
ItSomeBy/ints_10-4         2227.5n ± 43%   187.1n ± 14%  -91.60% (p=0.000 n=8)
ItSomeBy/ints_100-4         4.611µ ± 22%   1.691µ ± 10%  -63.32% (p=0.000 n=8)
ItSomeBy/ints_1000-4        39.41µ ± 27%   22.61µ ± 24%  -42.63% (p=0.000 n=8)
ItNoneBy/ints_10-4         1657.5n ± 34%   196.3n ± 21%  -88.15% (p=0.000 n=8)
ItNoneBy/ints_100-4         4.503µ ± 20%   1.743µ ± 12%  -61.30% (p=0.000 n=8)
ItNoneBy/ints_1000-4        29.39µ ± 29%   16.66µ ± 15%  -43.32% (p=0.000 n=8)
geomean                     5.591µ         1.747µ        -68.76%

                         │  old.txt   │               new.txt                │
                         │    B/op    │   B/op    vs base                    │
ItContainsBy/ints_10-4     200.0 ± 0%   0.0 ± 0%  -100.00% (p=0.000 n=8)
ItContainsBy/ints_100-4    200.0 ± 0%   0.0 ± 0%  -100.00% (p=0.000 n=8)
ItContainsBy/ints_1000-4   200.0 ± 0%   0.0 ± 0%  -100.00% (p=0.000 n=8)
ItEveryBy/ints_10-4        184.0 ± 0%   0.0 ± 0%  -100.00% (p=0.000 n=8)
ItEveryBy/ints_100-4       184.0 ± 0%   0.0 ± 0%  -100.00% (p=0.000 n=8)
ItEveryBy/ints_1000-4      184.0 ± 0%   0.0 ± 0%  -100.00% (p=0.000 n=8)
ItSomeBy/ints_10-4         200.0 ± 0%   0.0 ± 0%  -100.00% (p=0.000 n=8)
ItSomeBy/ints_100-4        200.0 ± 0%   0.0 ± 0%  -100.00% (p=0.000 n=8)
ItSomeBy/ints_1000-4       200.0 ± 0%   0.0 ± 0%  -100.00% (p=0.000 n=8)
ItNoneBy/ints_10-4         200.0 ± 0%   0.0 ± 0%  -100.00% (p=0.000 n=8)
ItNoneBy/ints_100-4        200.0 ± 0%   0.0 ± 0%  -100.00% (p=0.000 n=8)
ItNoneBy/ints_1000-4       200.0 ± 0%   0.0 ± 0%  -100.00% (p=0.000 n=8)

                         │  old.txt   │                new.txt                 │
                         │ allocs/op  │ allocs/op   vs base                    │
ItContainsBy/ints_10-4     7.000 ± 0%   0.000 ± 0%  -100.00% (p=0.000 n=8)
ItContainsBy/ints_100-4    7.000 ± 0%   0.000 ± 0%  -100.00% (p=0.000 n=8)
ItContainsBy/ints_1000-4   7.000 ± 0%   0.000 ± 0%  -100.00% (p=0.000 n=8)
ItEveryBy/ints_10-4        6.000 ± 0%   0.000 ± 0%  -100.00% (p=0.000 n=8)
ItEveryBy/ints_100-4       6.000 ± 0%   0.000 ± 0%  -100.00% (p=0.000 n=8)
ItEveryBy/ints_1000-4      6.000 ± 0%   0.000 ± 0%  -100.00% (p=0.000 n=8)
ItSomeBy/ints_10-4         7.000 ± 0%   0.000 ± 0%  -100.00% (p=0.000 n=8)
ItSomeBy/ints_100-4        7.000 ± 0%   0.000 ± 0%  -100.00% (p=0.000 n=8)
ItSomeBy/ints_1000-4       7.000 ± 0%   0.000 ± 0%  -100.00% (p=0.000 n=8)
ItNoneBy/ints_10-4         7.000 ± 0%   0.000 ± 0%  -100.00% (p=0.000 n=8)
ItNoneBy/ints_100-4        7.000 ± 0%   0.000 ± 0%  -100.00% (p=0.000 n=8)
ItNoneBy/ints_1000-4       7.000 ± 0%   0.000 ± 0%  -100.00% (p=0.000 n=8)

Co-authored-by: Samuel Berthe <dev@samuel-berthe.fr>
2026-02-24 20:26:59 +01:00
..