[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 13:27:18 PDT 2025
imdj wrote:
> @imdj What is your `lit` invocation for running the benchmark? Are you enabling optimizations?
>
> Per https://libcxx.llvm.org/TestingLibcxx.html#benchmarks:
>
> ```
> libcxx/utils/libcxx-lit <build> libcxx/test/benchmarks/algorithms/nonmodifying/is_permutation.bench.cpp --show-all --param optimization=speed
> ```
Yep, the exact workflow. Then I compare my PR build against a fairly up-to-date llvm main repo. using `libcxx/utils/libcxx-compare-benchmarks`.
Note all previous benchmarks were with the Debug build, I just tested again with Release and the performance was worse than base llvm, which I didn't expect.
<details>
<summary>Result: </summary>
```
Benchmark Time CPU Time Old Time New CPU Old CPU New
-----------------------------------------------------------------------------------------------------------------------------------------------------------------
std::is_permutation(vector<int>) (3leg) (common prefix)/8 -0.0000 -0.0002 6 6 6 6
std::is_permutation(vector<int>) (3leg) (common prefix)/1024 -0.0009 -0.0009 529 529 529 529
std::is_permutation(vector<int>) (3leg) (common prefix)/8192 -0.0002 -0.0003 4140 4139 4140 4139
std::is_permutation(deque<int>) (3leg) (common prefix)/8 -0.0000 +0.0000 21 21 21 21
std::is_permutation(deque<int>) (3leg) (common prefix)/1024 -0.1633 -0.1634 2480 2075 2480 2075
std::is_permutation(deque<int>) (3leg) (common prefix)/8192 -0.1649 -0.1649 19859 16584 19858 16584
std::is_permutation(list<int>) (3leg) (common prefix)/8 -0.0001 +0.0002 9 9 9 9
std::is_permutation(list<int>) (3leg) (common prefix)/1024 +0.0025 +0.0025 3848 3857 3848 3857
std::is_permutation(list<int>) (3leg) (common prefix)/8192 +0.0081 +0.0080 42126 42469 42124 42460
std::is_permutation(vector<int>) (3leg, pred) (common prefix)/8 -0.0043 -0.0042 7 7 7 7
std::is_permutation(vector<int>) (3leg, pred) (common prefix)/1024 -0.0007 -0.0004 631 631 631 631
std::is_permutation(vector<int>) (3leg, pred) (common prefix)/8192 -0.0193 -0.0196 5104 5005 5103 5003
std::is_permutation(deque<int>) (3leg, pred) (common prefix)/8 +0.0881 +0.0883 16 18 16 18
std::is_permutation(deque<int>) (3leg, pred) (common prefix)/1024 +0.0009 +0.0009 1256 1257 1256 1257
std::is_permutation(deque<int>) (3leg, pred) (common prefix)/8192 +0.0001 +0.0001 9978 9979 9978 9979
std::is_permutation(list<int>) (3leg, pred) (common prefix)/8 -0.0004 -0.0001 10 10 10 10
std::is_permutation(list<int>) (3leg, pred) (common prefix)/1024 +0.0003 +0.0003 4191 4193 4191 4192
std::is_permutation(list<int>) (3leg, pred) (common prefix)/8192 +0.0245 +0.0245 40886 41886 40883 41886
std::is_permutation(vector<int>) (4leg) (common prefix)/8 -0.0000 +0.0000 14 14 14 14
std::is_permutation(vector<int>) (4leg) (common prefix)/1024 -0.0002 +0.0000 842 842 842 842
std::is_permutation(vector<int>) (4leg) (common prefix)/8192 -0.0063 -0.0064 6648 6607 6648 6605
std::is_permutation(deque<int>) (4leg) (common prefix)/8 +0.0501 +0.0503 35 37 35 37
std::is_permutation(deque<int>) (4leg) (common prefix)/1024 +0.1019 +0.1016 2499 2753 2498 2752
std::is_permutation(deque<int>) (4leg) (common prefix)/8192 +0.0111 +0.0114 22057 22301 22050 22301
std::is_permutation(list<int>) (4leg) (common prefix)/8 -0.0311 -0.0313 13 12 13 12
std::is_permutation(list<int>) (4leg) (common prefix)/1024 +0.0017 +0.0019 3877 3884 3876 3884
std::is_permutation(list<int>) (4leg) (common prefix)/8192 +0.0250 +0.0248 40968 41990 40963 41981
rng::is_permutation(vector<int>) (4leg) (common prefix)/8 -0.0001 +0.0002 15 15 15 15
rng::is_permutation(vector<int>) (4leg) (common prefix)/1024 +0.0003 +0.0002 843 843 843 843
rng::is_permutation(vector<int>) (4leg) (common prefix)/8192 -0.0065 -0.0064 6648 6605 6647 6605
rng::is_permutation(deque<int>) (4leg) (common prefix)/8 +0.0044 +0.0043 37 37 37 37
rng::is_permutation(deque<int>) (4leg) (common prefix)/1024 -0.0004 -0.0002 2908 2907 2907 2907
rng::is_permutation(deque<int>) (4leg) (common prefix)/8192 +0.0005 +0.0004 23176 23188 23174 23183
rng::is_permutation(list<int>) (4leg) (common prefix)/8 -0.0307 -0.0306 14 13 14 13
rng::is_permutation(list<int>) (4leg) (common prefix)/1024 +0.0077 +0.0075 3824 3854 3824 3853
rng::is_permutation(list<int>) (4leg) (common prefix)/8192 +0.0231 +0.0233 40992 41937 40981 41936
std::is_permutation(vector<int>) (4leg, pred) (common prefix)/8 -0.0058 -0.0057 11 11 11 11
std::is_permutation(vector<int>) (4leg, pred) (common prefix)/1024 -0.0000 +0.0000 838 838 838 838
std::is_permutation(vector<int>) (4leg, pred) (common prefix)/8192 -0.0097 -0.0094 6667 6602 6665 6602
std::is_permutation(deque<int>) (4leg, pred) (common prefix)/8 +0.0489 +0.0488 33 34 33 34
std::is_permutation(deque<int>) (4leg, pred) (common prefix)/1024 +0.3932 +0.3935 2083 2902 2083 2902
std::is_permutation(deque<int>) (4leg, pred) (common prefix)/8192 +0.3959 +0.3958 16585 23151 16583 23147
std::is_permutation(list<int>) (4leg, pred) (common prefix)/8 -0.0002 +0.0002 12 12 12 12
std::is_permutation(list<int>) (4leg, pred) (common prefix)/1024 +0.0138 +0.0137 3824 3877 3823 3876
std::is_permutation(list<int>) (4leg, pred) (common prefix)/8192 +0.0246 +0.0249 41094 42104 41082 42104
rng::is_permutation(vector<int>) (4leg, pred) (common prefix)/8 +0.0001 -0.0000 11 11 11 11
rng::is_permutation(vector<int>) (4leg, pred) (common prefix)/1024 -0.0005 -0.0003 838 838 838 838
rng::is_permutation(vector<int>) (4leg, pred) (common prefix)/8192 -0.0092 -0.0093 6664 6603 6664 6601
rng::is_permutation(deque<int>) (4leg, pred) (common prefix)/8 +0.1557 +0.1560 33 38 33 38
rng::is_permutation(deque<int>) (4leg, pred) (common prefix)/1024 +0.3953 +0.3950 2083 2906 2083 2906
rng::is_permutation(deque<int>) (4leg, pred) (common prefix)/8192 +0.3964 +0.3964 16586 23161 16585 23160
rng::is_permutation(list<int>) (4leg, pred) (common prefix)/8 +0.0004 +0.0004 12 12 12 12
rng::is_permutation(list<int>) (4leg, pred) (common prefix)/1024 +0.0023 +0.0023 3874 3883 3874 3883
rng::is_permutation(list<int>) (4leg, pred) (common prefix)/8192 +0.0250 +0.0247 40947 41970 40945 41957
std::is_permutation(vector<int>) (3leg) (shuffled)/8 +0.0299 +0.0299 96 99 96 99
std::is_permutation(vector<int>) (3leg) (shuffled)/1024 -0.0133 -0.0131 708120 698686 707907 698654
std::is_permutation(deque<int>) (3leg) (shuffled)/8 +0.0100 +0.0101 220 222 220 222
std::is_permutation(deque<int>) (3leg) (shuffled)/1024 -0.0004 -0.0001 2987060 2985934 2986145 2985801
std::is_permutation(list<int>) (3leg) (shuffled)/8 +0.0008 +0.0009 174 174 174 174
std::is_permutation(list<int>) (3leg) (shuffled)/1024 +0.4320 +0.4322 4536223 6495823 4534804 6494671
std::is_permutation(vector<int>) (3leg, pred) (shuffled)/8 +0.0286 +0.0287 135 139 135 139
std::is_permutation(vector<int>) (3leg, pred) (shuffled)/1024 +0.0001 +0.0004 1977261 1977432 1976307 1977047
std::is_permutation(deque<int>) (3leg, pred) (shuffled)/8 -0.2500 -0.2499 246 185 246 185
std::is_permutation(deque<int>) (3leg, pred) (shuffled)/1024 -0.3224 -0.3221 3200019 2168258 3198364 2168258
std::is_permutation(list<int>) (3leg, pred) (shuffled)/8 +0.0130 +0.0130 126 127 126 127
std::is_permutation(list<int>) (3leg, pred) (shuffled)/1024 -0.0013 -0.0012 4900625 4894209 4899177 4893264
std::is_permutation(vector<int>) (4leg) (shuffled)/8 -0.0117 -0.0117 96 95 96 95
std::is_permutation(vector<int>) (4leg) (shuffled)/1024 -0.0007 -0.0005 700691 700200 700526 700183
std::is_permutation(deque<int>) (4leg) (shuffled)/8 +0.0004 +0.0003 234 234 234 234
std::is_permutation(deque<int>) (4leg) (shuffled)/1024 -0.0002 -0.0000 3195038 3194242 3194230 3194181
std::is_permutation(list<int>) (4leg) (shuffled)/8 -0.0014 -0.0016 178 178 178 178
std::is_permutation(list<int>) (4leg) (shuffled)/1024 +0.0087 +0.0090 4538545 4578236 4537479 4578150
rng::is_permutation(vector<int>) (4leg) (shuffled)/8 -0.0114 -0.0116 98 97 98 97
rng::is_permutation(vector<int>) (4leg) (shuffled)/1024 -0.0061 -0.0060 702060 697802 702016 697802
rng::is_permutation(deque<int>) (4leg) (shuffled)/8 -0.0690 -0.0692 237 221 237 221
rng::is_permutation(deque<int>) (4leg) (shuffled)/1024 -0.0662 -0.0661 3196098 2984646 3195895 2984647
rng::is_permutation(list<int>) (4leg) (shuffled)/8 -0.0008 -0.0009 178 178 178 178
rng::is_permutation(list<int>) (4leg) (shuffled)/1024 +0.0123 +0.0124 4529304 4585180 4528977 4585181
std::is_permutation(vector<int>) (4leg, pred) (shuffled)/8 +0.0597 +0.0596 114 121 114 121
std::is_permutation(vector<int>) (4leg, pred) (shuffled)/1024 -0.0003 -0.0003 1612183 1611671 1612039 1611630
std::is_permutation(deque<int>) (4leg, pred) (shuffled)/8 -0.2130 -0.2129 230 181 230 181
std::is_permutation(deque<int>) (4leg, pred) (shuffled)/1024 -0.3067 -0.3067 3197632 2216939 3197364 2216881
std::is_permutation(list<int>) (4leg, pred) (shuffled)/8 -0.0919 -0.0916 141 128 141 128
std::is_permutation(list<int>) (4leg, pred) (shuffled)/1024 +0.0116 +0.0114 5008590 5066460 5008282 5065440
rng::is_permutation(vector<int>) (4leg, pred) (shuffled)/8 +0.0486 +0.0488 114 120 114 120
rng::is_permutation(vector<int>) (4leg, pred) (shuffled)/1024 +0.0011 +0.0009 1612081 1613776 1611943 1613421
rng::is_permutation(deque<int>) (4leg, pred) (shuffled)/8 +0.0017 +0.0017 216 216 216 216
rng::is_permutation(deque<int>) (4leg, pred) (shuffled)/1024 -0.0028 -0.0030 2907944 2899692 2907738 2899074
rng::is_permutation(list<int>) (4leg, pred) (shuffled)/8 -0.0286 -0.0285 132 128 132 128
rng::is_permutation(list<int>) (4leg, pred) (shuffled)/1024 +0.0136 +0.0139 5022191 5090386 5020599 5090284
OVERALL_GEOMEAN +0.0049 +0.0049 0 0 0 0
```
</details>
https://github.com/llvm/llvm-project/pull/129565
More information about the libcxx-commits
mailing list