[libcxx-commits] [libcxx] [libc++] Tiny optimizations for is_permutation (PR #129565)

Imad Aldij via libcxx-commits libcxx-commits at lists.llvm.org
Thu Mar 20 07:26:23 PDT 2025


imdj wrote:

This are the benchmark results I'm getting now after adding the second mismatch and incorporating #132090 and #132090 locally.

<details>

<summary>Results:</summary>

```
Benchmark                                                                            Time             CPU      Time Old      Time New       CPU Old       CPU New
-----------------------------------------------------------------------------------------------------------------------------------------------------------------
std::is_permutation(vector<int>) (3leg) (common prefix)/8                         -0.0089         -0.0088             6             6             6             6
std::is_permutation(vector<int>) (3leg) (common prefix)/1024                      +0.0001         +0.0002           529           529           529           529
std::is_permutation(vector<int>) (3leg) (common prefix)/8192                      +0.0001         +0.0001          4140          4141          4139          4140
std::is_permutation(deque<int>) (3leg) (common prefix)/8                          +0.0002         +0.0002            21            21            21            21
std::is_permutation(deque<int>) (3leg) (common prefix)/1024                       -0.1635         -0.1635          2481          2075          2480          2075
std::is_permutation(deque<int>) (3leg) (common prefix)/8192                       -0.1654         -0.1654         19863         16577         19863         16577
std::is_permutation(list<int>) (3leg) (common prefix)/8                           +0.0014         +0.0014             9             9             9             9
std::is_permutation(list<int>) (3leg) (common prefix)/1024                        -0.0007         -0.0007          3863          3860          3863          3860
std::is_permutation(list<int>) (3leg) (common prefix)/8192                        -0.0119         -0.0118         42229         41729         42219         41719
std::is_permutation(vector<int>) (3leg, pred) (common prefix)/8                   +0.0017         +0.0017             7             7             7             7
std::is_permutation(vector<int>) (3leg, pred) (common prefix)/1024                +0.0001         +0.0002           631           631           631           631
std::is_permutation(vector<int>) (3leg, pred) (common prefix)/8192                +0.0008         +0.0008          4961          4965          4961          4965
std::is_permutation(deque<int>) (3leg, pred) (common prefix)/8                    +0.0886         +0.0886            16            18            16            18
std::is_permutation(deque<int>) (3leg, pred) (common prefix)/1024                 +0.0017         +0.0015          1256          1258          1256          1258
std::is_permutation(deque<int>) (3leg, pred) (common prefix)/8192                 -0.0101         -0.0101         10086          9985         10086          9984
std::is_permutation(list<int>) (3leg, pred) (common prefix)/8                     -0.0001         -0.0001            10            10            10            10
std::is_permutation(list<int>) (3leg, pred) (common prefix)/1024                  +0.0034         +0.0034          4194          4209          4194          4209
std::is_permutation(list<int>) (3leg, pred) (common prefix)/8192                  -0.0299         -0.0301         41928         40673         41927         40664
std::is_permutation(vector<int>) (4leg) (common prefix)/8                         +0.0101         +0.0101            14            14            14            14
std::is_permutation(vector<int>) (4leg) (common prefix)/1024                      -0.0004         -0.0002           843           842           842           842
std::is_permutation(vector<int>) (4leg) (common prefix)/8192                      +0.0001         +0.0003          6607          6607          6605          6607
std::is_permutation(deque<int>) (4leg) (common prefix)/8                          +0.0526         +0.0528            35            37            35            37
std::is_permutation(deque<int>) (4leg) (common prefix)/1024                       +0.1007         +0.1008          2500          2751          2500          2751
std::is_permutation(deque<int>) (4leg) (common prefix)/8192                       +0.0038         +0.0038         22227         22311         22222         22307
std::is_permutation(list<int>) (4leg) (common prefix)/8                           -0.0516         -0.0516            13            12            13            12
std::is_permutation(list<int>) (4leg) (common prefix)/1024                        -0.0036         -0.0036          3913          3899          3912          3898
std::is_permutation(list<int>) (4leg) (common prefix)/8192                        -0.0304         -0.0304         42040         40764         42039         40763
rng::is_permutation(vector<int>) (4leg) (common prefix)/8                         -0.0051         -0.0051            15            15            15            15
rng::is_permutation(vector<int>) (4leg) (common prefix)/1024                      +0.0002         +0.0002           843           843           843           843
rng::is_permutation(vector<int>) (4leg) (common prefix)/8192                      -0.0004         -0.0004          6610          6607          6609          6607
rng::is_permutation(deque<int>) (4leg) (common prefix)/8                          +0.0038         +0.0038            37            37            37            37
rng::is_permutation(deque<int>) (4leg) (common prefix)/1024                       -0.0006         -0.0006          2909          2907          2909          2907
rng::is_permutation(deque<int>) (4leg) (common prefix)/8192                       +0.0007         +0.0007         23177         23192         23176         23192
rng::is_permutation(list<int>) (4leg) (common prefix)/8                           -0.0303         -0.0304            14            13            14            13
rng::is_permutation(list<int>) (4leg) (common prefix)/1024                        -0.0017         -0.0019          3857          3851          3857          3850
rng::is_permutation(list<int>) (4leg) (common prefix)/8192                        -0.0288         -0.0288         41948         40739         41947         40738
std::is_permutation(vector<int>) (4leg, pred) (common prefix)/8                   +0.0001         -0.0001            11            11            11            11
std::is_permutation(vector<int>) (4leg, pred) (common prefix)/1024                +0.0003         +0.0003           838           838           838           838
std::is_permutation(vector<int>) (4leg, pred) (common prefix)/8192                +0.0007         +0.0007          6604          6608          6603          6607
std::is_permutation(deque<int>) (4leg, pred) (common prefix)/8                    +0.0504         +0.0504            33            34            33            34
std::is_permutation(deque<int>) (4leg, pred) (common prefix)/1024                 +0.3967         +0.3964          2083          2909          2083          2908
std::is_permutation(deque<int>) (4leg, pred) (common prefix)/8192                 +0.3952         +0.3950         16593         23151         16592         23146
std::is_permutation(list<int>) (4leg, pred) (common prefix)/8                     +0.0000         +0.0000            12            12            12            12
std::is_permutation(list<int>) (4leg, pred) (common prefix)/1024                  -0.0051         -0.0051          3872          3852          3872          3852
std::is_permutation(list<int>) (4leg, pred) (common prefix)/8192                  -0.0293         -0.0293         42144         40908         42133         40899
rng::is_permutation(vector<int>) (4leg, pred) (common prefix)/8                   +0.0052         +0.0052            11            11            11            11
rng::is_permutation(vector<int>) (4leg, pred) (common prefix)/1024                +0.0000         -0.0002           838           838           838           838
rng::is_permutation(vector<int>) (4leg, pred) (common prefix)/8192                +0.0237         +0.0237          6603          6759          6603          6759
rng::is_permutation(deque<int>) (4leg, pred) (common prefix)/8                    +0.1165         +0.1165            33            37            33            37
rng::is_permutation(deque<int>) (4leg, pred) (common prefix)/1024                 +0.3948         +0.3948          2083          2906          2083          2906
rng::is_permutation(deque<int>) (4leg, pred) (common prefix)/8192                 +0.3983         +0.3983         16583         23188         16582         23187
rng::is_permutation(list<int>) (4leg, pred) (common prefix)/8                     +0.0007         +0.0007            12            12            12            12
rng::is_permutation(list<int>) (4leg, pred) (common prefix)/1024                  -0.0004         -0.0004          3882          3881          3882          3881
rng::is_permutation(list<int>) (4leg, pred) (common prefix)/8192                  -0.0288         -0.0288         41979         40770         41978         40769
std::is_permutation(vector<int>) (3leg) (shuffled)/8                              +0.0126         +0.0126            97            98            97            98
std::is_permutation(vector<int>) (3leg) (shuffled)/1024                           +0.0009         +0.0009        698680        699327        698523        699184
std::is_permutation(deque<int>) (3leg) (shuffled)/8                               +0.0164         +0.0164           220           224           220           224
std::is_permutation(deque<int>) (3leg) (shuffled)/1024                            +0.0004         +0.0004       2986223       2987287       2985635       2986691
std::is_permutation(list<int>) (3leg) (shuffled)/8                                +0.0011         +0.0011           174           174           174           174
std::is_permutation(list<int>) (3leg) (shuffled)/1024                             -0.0015         -0.0015       4585000       4578319       4584252       4577380
std::is_permutation(vector<int>) (3leg, pred) (shuffled)/8                        +0.0333         +0.0334           135           139           135           139
std::is_permutation(vector<int>) (3leg, pred) (shuffled)/1024                     +0.0009         +0.0009       1976553       1978340       1976050       1977906
std::is_permutation(deque<int>) (3leg, pred) (shuffled)/8                         -0.2380         -0.2380           241           184           241           184
std::is_permutation(deque<int>) (3leg, pred) (shuffled)/1024                      -0.3217         -0.3217       3198900       2169813       3198126       2169347
std::is_permutation(list<int>) (3leg, pred) (shuffled)/8                          +0.0170         +0.0172           125           127           125           127
std::is_permutation(list<int>) (3leg, pred) (shuffled)/1024                       -0.0017         -0.0016       4899881       4891630       4898641       4890573
std::is_permutation(vector<int>) (4leg) (shuffled)/8                              -0.0126         -0.0125            96            95            96            95
std::is_permutation(vector<int>) (4leg) (shuffled)/1024                           +0.0004         +0.0004        700149        700446        700132        700446
std::is_permutation(deque<int>) (4leg) (shuffled)/8                               +0.0041         +0.0041           234           235           234           235
std::is_permutation(deque<int>) (4leg) (shuffled)/1024                            +0.0003         +0.0004       3193933       3194955       3193682       3194899
std::is_permutation(list<int>) (4leg) (shuffled)/8                                +0.0029         +0.0029           178           178           178           178
std::is_permutation(list<int>) (4leg) (shuffled)/1024                             -0.0031         -0.0030       4586281       4572054       4584761       4571155
rng::is_permutation(vector<int>) (4leg) (shuffled)/8                              -0.0140         -0.0140            99            97            99            97
rng::is_permutation(vector<int>) (4leg) (shuffled)/1024                           +0.0001         +0.0000        698294        698336        698288        698315
rng::is_permutation(deque<int>) (4leg) (shuffled)/8                               -0.0699         -0.0699           237           221           237           221
rng::is_permutation(deque<int>) (4leg) (shuffled)/1024                            -0.0660         -0.0660       3195729       2984915       3195573       2984812
rng::is_permutation(list<int>) (4leg) (shuffled)/8                                -0.0006         -0.0005           178           178           178           178
rng::is_permutation(list<int>) (4leg) (shuffled)/1024                             -0.0026         -0.0024       4586701       4574790       4585880       4574676
std::is_permutation(vector<int>) (4leg, pred) (shuffled)/8                        +0.0573         +0.0573           114           121           114           121
std::is_permutation(vector<int>) (4leg, pred) (shuffled)/1024                     -0.0005         -0.0004       1610369       1609640       1610279       1609599
std::is_permutation(deque<int>) (4leg, pred) (shuffled)/8                         -0.2122         -0.2122           230           181           230           181
std::is_permutation(deque<int>) (4leg, pred) (shuffled)/1024                      -0.3077         -0.3077       3197346       2213480       3197042       2213402
std::is_permutation(list<int>) (4leg, pred) (shuffled)/8                          -0.0892         -0.0890           141           128           141           128
std::is_permutation(list<int>) (4leg, pred) (shuffled)/1024                       +0.0096         +0.0096       5003662       5051572       5003320       5051456
rng::is_permutation(vector<int>) (4leg, pred) (shuffled)/8                        +0.0586         +0.0586           114           121           114           121
rng::is_permutation(vector<int>) (4leg, pred) (shuffled)/1024                     +0.0020         +0.0018       1607373       1610551       1607305       1610201
rng::is_permutation(deque<int>) (4leg, pred) (shuffled)/8                         +0.0090         +0.0088           214           216           214           216
rng::is_permutation(deque<int>) (4leg, pred) (shuffled)/1024                      +0.0059         +0.0056       2883862       2901004       2883558       2899833
rng::is_permutation(list<int>) (4leg, pred) (shuffled)/8                          -0.0405         -0.0407           133           128           133           128
rng::is_permutation(list<int>) (4leg, pred) (shuffled)/1024                       +0.0086         +0.0086       5020501       5063769       5019298       5062632
OVERALL_GEOMEAN                                                                   -0.0022         -0.0022             0             0             0             0
```
</details>

https://github.com/llvm/llvm-project/pull/129565


More information about the libcxx-commits mailing list