[libcxx-commits] [PATCH] D127557: [libc++][ranges] Implement `ranges::sort`.
Konstantin Varlamov via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Jun 14 01:28:19 PDT 2022
var-const added a comment.
> I'm fearing that the custom comparator interferes with the branchless sorting for arithmetic types. If that is the case it should show up in the benchmarks.
@philnik Can you name a specific benchmark where this would show up? Perhaps we should just compare the assembly?
================
Comment at: libcxx/include/__algorithm/ranges_sort.h:37
+struct __fn {
+ template <random_access_iterator _Iter, sentinel_for<_Iter> _Sent, class _Comp = ranges::less, class _Proj = identity>
+ requires sortable<_Iter, _Comp, _Proj>
----------------
philnik wrote:
> Just a thought, and this should probably be done in a follow-up patch: Do we want to specialize this if `is_same_v<_Comp, ranges::less> && is_same_v<_Proj, identity>`? That is probably the normal use case and it would avoid code duplication. `sort` is quite large.
Thanks, it's an interesting idea -- will do in a follow-up.
================
Comment at: libcxx/include/__algorithm/ranges_sort.h:41-45
+ auto __projected_comp = [&](auto&& __lhs, auto&& __rhs) {
+ return std::invoke(__comp,
+ std::invoke(__proj, std::forward<decltype(__lhs)>(__lhs)),
+ std::invoke(__proj, std::forward<decltype(__rhs)>(__rhs)));
+ };
----------------
philnik wrote:
> This is valid because `sortable` guarantees that the same object with different cv-ref qualifications compares identical. To be precise, `sortable` -> `strict_weak_order` -> `relation` -> `predicate` is the chain to follow for this information from https://en.cppreference.com/w/cpp/iterator/sortable.
This is very interesting, can you elaborate a bit? I couldn't easily see the part about cv-qualifications after reading through the chain on cppreference.
================
Comment at: libcxx/include/__algorithm/ranges_sort.h:47
+
+ if constexpr (std::same_as<_Iter, _Sent>) {
+ std::__sort_impl(std::move(__first), __last, __projected_comp);
----------------
philnik wrote:
> This is unnecessary. `ranges::next` already checks for `assignable_from<_Ip&, _Sp>` and in that case just returns the sentinel.
This version avoids having an additional variable altogether (including the unoptimized build). But I do think it's probably overkill, removed.
================
Comment at: libcxx/test/std/algorithms/alg.sorting/alg.sort/sort/ranges.sort.pass.cpp:1
+//===----------------------------------------------------------------------===//
+//
----------------
philnik wrote:
> Could you also add a benchmark for `ranges::sort` and make sure the numbers are within margin of error compared to `std::sort`? It would be really bad if the ranges version performed worse than the classic STL version.
Added a benchmark, but it looks like there's too much random variation on my machine for a meaningful comparison. Perhaps you'd be interested to run the two benchmarks on your machine?
There are ~300 benchmarks (288, to be precise). About 3/4 of those are faster with the ranges version (even 10 times faster in a few instances), but about 1/4 are slower. Most of the slower ones are within 15-20% of the classic version, but some are 2.5-3 times slower (e.g. `BM_Sort_string_SingleElement_16384`). I don't see any obvious pattern and also no reason for the ranges version to outperform the non-ranges version -- either I'm doing something wrong, or these benchmarks contain too much random variation to do a meaningful comparison.
Pasting the raw numbers below. I'm omitting the name of the ranges benchmark (it's always equivalent to the non-ranges one) and wall time. The columns are: benchmark name / classic CPU time, ns / ranges CPU time, ns / ranges CPU time divided by classic CPU time, %
```
BM_Sort_uint32_Random_1 6.76 3.41 50.44%
BM_Sort_uint32_Random_4 15.3 4.09 26.73%
BM_Sort_uint32_Random_16 30.5 8.04 26.36%
BM_Sort_uint32_Random_64 51 14.9 29.22%
BM_Sort_uint32_Random_256 67.8 21.3 31.42%
BM_Sort_uint32_Random_1024 84.3 27.7 32.86%
BM_Sort_uint32_Random_16384 116 40.4 34.83%
BM_Sort_uint32_Random_262144 149 52.9 35.50%
BM_Sort_uint32_Ascending_1 6.7 3.44 51.34%
BM_Sort_uint32_Ascending_4 9.07 1.19 13.12%
BM_Sort_uint32_Ascending_16 4.13 0.713 17.26%
BM_Sort_uint32_Ascending_64 6 1.46 24.33%
BM_Sort_uint32_Ascending_256 4.99 1.58 31.66%
BM_Sort_uint32_Ascending_1024 4.76 1.51 31.72%
BM_Sort_uint32_Ascending_16384 4.66 1.44 30.90%
BM_Sort_uint32_Ascending_262144 4.68 1.45 30.98%
BM_Sort_uint32_Descending_1 6.85 3.41 49.78%
BM_Sort_uint32_Descending_4 9.09 1.41 15.51%
BM_Sort_uint32_Descending_16 37 3.04 8.22%
BM_Sort_uint32_Descending_64 11.4 2.32 20.35%
BM_Sort_uint32_Descending_256 10.4 2.44 23.46%
BM_Sort_uint32_Descending_1024 12.3 2.67 21.71%
BM_Sort_uint32_Descending_16384 12.5 2.47 19.76%
BM_Sort_uint32_Descending_262144 11.7 2.46 21.03%
BM_Sort_uint32_SingleElement_1 6.68 3.39 50.75%
BM_Sort_uint32_SingleElement_4 9.15 1.18 12.90%
BM_Sort_uint32_SingleElement_16 3.62 0.71 19.61%
BM_Sort_uint32_SingleElement_64 5.13 0.792 15.44%
BM_Sort_uint32_SingleElement_256 4.73 0.668 14.12%
BM_Sort_uint32_SingleElement_1024 4.66 0.626 13.43%
BM_Sort_uint32_SingleElement_16384 4.55 0.55 12.09%
BM_Sort_uint32_SingleElement_262144 4.56 0.548 12.02%
BM_Sort_uint32_PipeOrgan_1 6.65 3.44 51.73%
BM_Sort_uint32_PipeOrgan_4 9.09 1.24 13.64%
BM_Sort_uint32_PipeOrgan_16 11.9 1.61 13.53%
BM_Sort_uint32_PipeOrgan_64 36.4 3.66 10.05%
BM_Sort_uint32_PipeOrgan_256 15.4 2.69 17.47%
BM_Sort_uint32_PipeOrgan_1024 19.6 3.31 16.89%
BM_Sort_uint32_PipeOrgan_16384 24.5 3.83 15.63%
BM_Sort_uint32_PipeOrgan_262144 30.1 4.48 14.88%
BM_Sort_uint32_QuickSortAdversary_1 6.73 3.38 50.22%
BM_Sort_uint32_QuickSortAdversary_4 9.19 1.17 12.73%
BM_Sort_uint32_QuickSortAdversary_16 4.12 0.708 17.18%
BM_Sort_uint32_QuickSortAdversary_64 62.1 8.71 14.03%
BM_Sort_uint32_QuickSortAdversary_256 116 11.1 9.57%
BM_Sort_uint32_QuickSortAdversary_1024 176 29.3 16.65%
BM_Sort_uint32_QuickSortAdversary_16384 249 51.7 20.76%
BM_Sort_uint32_QuickSortAdversary_262144 306 58 18.95%
BM_Sort_uint64_Random_1 6.84 3.66 53.51%
BM_Sort_uint64_Random_4 15.7 4.36 27.77%
BM_Sort_uint64_Random_16 31.4 8.36 26.62%
BM_Sort_uint64_Random_64 51.2 15.1 29.49%
BM_Sort_uint64_Random_256 70.1 21.5 30.67%
BM_Sort_uint64_Random_1024 85.3 27.7 32.47%
BM_Sort_uint64_Random_16384 118 40.2 34.07%
BM_Sort_uint64_Random_262144 150 52.4 34.93%
BM_Sort_uint64_Ascending_1 6.92 3.4 49.13%
BM_Sort_uint64_Ascending_4 9.23 1.09 11.81%
BM_Sort_uint64_Ascending_16 3.65 0.721 19.75%
BM_Sort_uint64_Ascending_64 6.4 1.13 17.66%
BM_Sort_uint64_Ascending_256 5.17 1.27 24.56%
BM_Sort_uint64_Ascending_1024 4.99 1.2 24.05%
BM_Sort_uint64_Ascending_16384 4.7 1.14 24.26%
BM_Sort_uint64_Ascending_262144 4.62 1.13 24.46%
BM_Sort_uint64_Descending_1 6.67 3.61 54.12%
BM_Sort_uint64_Descending_4 9.25 1.45 15.68%
BM_Sort_uint64_Descending_16 36.9 2.86 7.75%
BM_Sort_uint64_Descending_64 12 2.12 17.67%
BM_Sort_uint64_Descending_256 11 2.03 18.45%
BM_Sort_uint64_Descending_1024 12.9 2.23 17.29%
BM_Sort_uint64_Descending_16384 12 2.06 17.17%
BM_Sort_uint64_Descending_262144 12 2.18 18.17%
BM_Sort_uint64_SingleElement_1 6.59 3.38 51.29%
BM_Sort_uint64_SingleElement_4 9.21 1.09 11.83%
BM_Sort_uint64_SingleElement_16 3.64 0.715 19.64%
BM_Sort_uint64_SingleElement_64 5.27 0.887 16.83%
BM_Sort_uint64_SingleElement_256 4.77 1.07 22.43%
BM_Sort_uint64_SingleElement_1024 4.73 0.923 19.51%
BM_Sort_uint64_SingleElement_16384 4.55 0.921 20.24%
BM_Sort_uint64_SingleElement_262144 4.59 0.938 20.44%
BM_Sort_uint64_PipeOrgan_1 6.65 3.6 54.14%
BM_Sort_uint64_PipeOrgan_4 9.06 1.14 12.58%
BM_Sort_uint64_PipeOrgan_16 12 1.41 11.75%
BM_Sort_uint64_PipeOrgan_64 36.8 3.47 9.43%
BM_Sort_uint64_PipeOrgan_256 15.4 2.56 16.62%
BM_Sort_uint64_PipeOrgan_1024 19.5 3.21 16.46%
BM_Sort_uint64_PipeOrgan_16384 24.4 3.78 15.49%
BM_Sort_uint64_PipeOrgan_262144 29.8 4.58 15.37%
BM_Sort_uint64_QuickSortAdversary_1 6.76 3.5 51.78%
BM_Sort_uint64_QuickSortAdversary_4 9.03 1.09 12.07%
BM_Sort_uint64_QuickSortAdversary_16 3.73 0.717 19.22%
BM_Sort_uint64_QuickSortAdversary_64 66.8 8.99 13.46%
BM_Sort_uint64_QuickSortAdversary_256 132 12 9.09%
BM_Sort_uint64_QuickSortAdversary_1024 189 30.5 16.14%
BM_Sort_uint64_QuickSortAdversary_16384 270 54.3 20.11%
BM_Sort_uint64_QuickSortAdversary_262144 326 68.2 20.92%
BM_Sort_pair<uint32, uint32>_Random_1 3.25 3.47 106.77%
BM_Sort_pair<uint32, uint32>_Random_4 5.67 5.91 104.23%
BM_Sort_pair<uint32, uint32>_Random_16 20.7 20.7 100.00%
BM_Sort_pair<uint32, uint32>_Random_64 31.2 30.5 97.76%
BM_Sort_pair<uint32, uint32>_Random_256 39.2 39.2 100.00%
BM_Sort_pair<uint32, uint32>_Random_1024 46.5 46.3 99.57%
BM_Sort_pair<uint32, uint32>_Random_16384 62.3 61.9 99.36%
BM_Sort_pair<uint32, uint32>_Random_262144 79.7 78.8 98.87%
BM_Sort_pair<uint32, uint32>_Ascending_1 3.19 4.15 130.09%
BM_Sort_pair<uint32, uint32>_Ascending_4 1.85 2.13 115.14%
BM_Sort_pair<uint32, uint32>_Ascending_16 2.42 2.46 101.65%
BM_Sort_pair<uint32, uint32>_Ascending_64 1.91 1.93 101.05%
BM_Sort_pair<uint32, uint32>_Ascending_256 1.99 2.02 101.51%
BM_Sort_pair<uint32, uint32>_Ascending_1024 1.91 1.96 102.62%
BM_Sort_pair<uint32, uint32>_Ascending_16384 1.82 1.87 102.75%
BM_Sort_pair<uint32, uint32>_Ascending_262144 1.82 1.85 101.65%
BM_Sort_pair<uint32, uint32>_Descending_1 3.2 3.71 115.94%
BM_Sort_pair<uint32, uint32>_Descending_4 2.56 2.56 100.00%
BM_Sort_pair<uint32, uint32>_Descending_16 5.45 5.26 96.51%
BM_Sort_pair<uint32, uint32>_Descending_64 4.35 3.94 90.57%
BM_Sort_pair<uint32, uint32>_Descending_256 3.79 3.52 92.88%
BM_Sort_pair<uint32, uint32>_Descending_1024 5.02 4.7 93.63%
BM_Sort_pair<uint32, uint32>_Descending_16384 4.78 4.5 94.14%
BM_Sort_pair<uint32, uint32>_Descending_262144 4.75 4.46 93.89%
BM_Sort_pair<uint32, uint32>_SingleElement_1 3.21 4.1 127.73%
BM_Sort_pair<uint32, uint32>_SingleElement_4 1.91 1.92 100.52%
BM_Sort_pair<uint32, uint32>_SingleElement_16 2.25 2.85 126.67%
BM_Sort_pair<uint32, uint32>_SingleElement_64 2.3 2.67 116.09%
BM_Sort_pair<uint32, uint32>_SingleElement_256 2.43 2.87 118.11%
BM_Sort_pair<uint32, uint32>_SingleElement_1024 2.3 2.71 117.83%
BM_Sort_pair<uint32, uint32>_SingleElement_16384 2.26 2.67 118.14%
BM_Sort_pair<uint32, uint32>_SingleElement_262144 2.27 2.66 117.18%
BM_Sort_pair<uint32, uint32>_PipeOrgan_1 3.18 3.63 114.15%
BM_Sort_pair<uint32, uint32>_PipeOrgan_4 2.18 2.21 101.38%
BM_Sort_pair<uint32, uint32>_PipeOrgan_16 5.27 5.14 97.53%
BM_Sort_pair<uint32, uint32>_PipeOrgan_64 5.65 5.64 99.82%
BM_Sort_pair<uint32, uint32>_PipeOrgan_256 7.51 7.46 99.33%
BM_Sort_pair<uint32, uint32>_PipeOrgan_1024 9.48 9.5 100.21%
BM_Sort_pair<uint32, uint32>_PipeOrgan_16384 10.6 10.6 100.00%
BM_Sort_pair<uint32, uint32>_PipeOrgan_262144 12.6 12.6 100.00%
BM_Sort_pair<uint32, uint32>_QuickSortAdversary_1 3.17 4.11 129.65%
BM_Sort_pair<uint32, uint32>_QuickSortAdversary_4 2.3 2.47 107.39%
BM_Sort_pair<uint32, uint32>_QuickSortAdversary_16 5.29 5.13 96.98%
BM_Sort_pair<uint32, uint32>_QuickSortAdversary_64 8.51 8.16 95.89%
BM_Sort_pair<uint32, uint32>_QuickSortAdversary_256 11.6 11.3 97.41%
BM_Sort_pair<uint32, uint32>_QuickSortAdversary_1024 14.1 13.3 94.33%
BM_Sort_pair<uint32, uint32>_QuickSortAdversary_16384 33.1 32.6 98.49%
BM_Sort_pair<uint32, uint32>_QuickSortAdversary_262144 38.3 37.9 98.96%
BM_Sort_tuple<uint32, uint64, uint32>_Random_1 3.48 4.36 125.29%
BM_Sort_tuple<uint32, uint64, uint32>_Random_4 6.27 6.57 104.78%
BM_Sort_tuple<uint32, uint64, uint32>_Random_16 25.6 24.6 96.09%
BM_Sort_tuple<uint32, uint64, uint32>_Random_64 38.2 35 91.62%
BM_Sort_tuple<uint32, uint64, uint32>_Random_256 45 41.1 91.33%
BM_Sort_tuple<uint32, uint64, uint32>_Random_1024 53.1 47.6 89.64%
BM_Sort_tuple<uint32, uint64, uint32>_Random_16384 67.8 60.3 88.94%
BM_Sort_tuple<uint32, uint64, uint32>_Random_262144 86.1 76.7 89.08%
BM_Sort_tuple<uint32, uint64, uint32>_Ascending_1 3.46 3.69 106.65%
BM_Sort_tuple<uint32, uint64, uint32>_Ascending_4 2.29 2.28 99.56%
BM_Sort_tuple<uint32, uint64, uint32>_Ascending_16 3.39 3.03 89.38%
BM_Sort_tuple<uint32, uint64, uint32>_Ascending_64 3.14 3.33 106.05%
BM_Sort_tuple<uint32, uint64, uint32>_Ascending_256 3.13 3.42 109.27%
BM_Sort_tuple<uint32, uint64, uint32>_Ascending_1024 3.08 3.34 108.44%
BM_Sort_tuple<uint32, uint64, uint32>_Ascending_16384 2.92 3.09 105.82%
BM_Sort_tuple<uint32, uint64, uint32>_Ascending_262144 3.11 3.24 104.18%
BM_Sort_tuple<uint32, uint64, uint32>_Descending_1 3.97 3.88 97.73%
BM_Sort_tuple<uint32, uint64, uint32>_Descending_4 3.93 3.28 83.46%
BM_Sort_tuple<uint32, uint64, uint32>_Descending_16 6.2 5.23 84.35%
BM_Sort_tuple<uint32, uint64, uint32>_Descending_64 5.26 4.64 88.21%
BM_Sort_tuple<uint32, uint64, uint32>_Descending_256 4.76 4.31 90.55%
BM_Sort_tuple<uint32, uint64, uint32>_Descending_1024 6.23 5.35 85.87%
BM_Sort_tuple<uint32, uint64, uint32>_Descending_16384 5.91 5.15 87.14%
BM_Sort_tuple<uint32, uint64, uint32>_Descending_262144 6.67 6.19 92.80%
BM_Sort_tuple<uint32, uint64, uint32>_SingleElement_1 3.5 3.69 105.43%
BM_Sort_tuple<uint32, uint64, uint32>_SingleElement_4 2.61 2.33 89.27%
BM_Sort_tuple<uint32, uint64, uint32>_SingleElement_16 3.43 3.31 96.50%
BM_Sort_tuple<uint32, uint64, uint32>_SingleElement_64 4.08 3.91 95.83%
BM_Sort_tuple<uint32, uint64, uint32>_SingleElement_256 4.35 4.29 98.62%
BM_Sort_tuple<uint32, uint64, uint32>_SingleElement_1024 4.17 4.18 100.24%
BM_Sort_tuple<uint32, uint64, uint32>_SingleElement_16384 3.8 3.79 99.74%
BM_Sort_tuple<uint32, uint64, uint32>_SingleElement_262144 3.83 3.84 100.26%
BM_Sort_tuple<uint32, uint64, uint32>_PipeOrgan_1 3.47 3.88 111.82%
BM_Sort_tuple<uint32, uint64, uint32>_PipeOrgan_4 2.46 2.52 102.44%
BM_Sort_tuple<uint32, uint64, uint32>_PipeOrgan_16 6.48 5.76 88.89%
BM_Sort_tuple<uint32, uint64, uint32>_PipeOrgan_64 7.46 6.55 87.80%
BM_Sort_tuple<uint32, uint64, uint32>_PipeOrgan_256 10.2 8.11 79.51%
BM_Sort_tuple<uint32, uint64, uint32>_PipeOrgan_1024 11.4 9.95 87.28%
BM_Sort_tuple<uint32, uint64, uint32>_PipeOrgan_16384 13 11.6 89.23%
BM_Sort_tuple<uint32, uint64, uint32>_PipeOrgan_262144 16 14.6 91.25%
BM_Sort_tuple<uint32, uint64, uint32>_QuickSortAdversary_1 3.49 3.69 105.73%
BM_Sort_tuple<uint32, uint64, uint32>_QuickSortAdversary_4 2.83 2.65 93.64%
BM_Sort_tuple<uint32, uint64, uint32>_QuickSortAdversary_16 6.3 5.21 82.70%
BM_Sort_tuple<uint32, uint64, uint32>_QuickSortAdversary_64 10.8 9.47 87.69%
BM_Sort_tuple<uint32, uint64, uint32>_QuickSortAdversary_256 15.4 12.7 82.47%
BM_Sort_tuple<uint32, uint64, uint32>_QuickSortAdversary_1024 23.4 19.5 83.33%
BM_Sort_tuple<uint32, uint64, uint32>_QuickSortAdversary_16384 47 41.4 88.09%
BM_Sort_tuple<uint32, uint64, uint32>_QuickSortAdversary_262144 54.5 46.3 84.95%
BM_Sort_string_Random_1 4.25 4.5 105.88%
BM_Sort_string_Random_4 16.7 16.4 98.20%
BM_Sort_string_Random_16 45.8 45.5 99.34%
BM_Sort_string_Random_64 71.1 69.8 98.17%
BM_Sort_string_Random_256 90.1 88.4 98.11%
BM_Sort_string_Random_1024 108 109 100.93%
BM_Sort_string_Random_16384 172 174 101.16%
BM_Sort_string_Random_262144 283 285 100.71%
BM_Sort_string_Ascending_1 4.23 4.8 113.48%
BM_Sort_string_Ascending_4 9.8 9.51 97.04%
BM_Sort_string_Ascending_16 16.6 16.8 101.20%
BM_Sort_string_Ascending_64 21.9 21.7 99.09%
BM_Sort_string_Ascending_256 21.4 21.1 98.60%
BM_Sort_string_Ascending_1024 21.1 20.9 99.05%
BM_Sort_string_Ascending_16384 38.7 35.1 90.70%
BM_Sort_string_Ascending_262144 45.4 43.6 96.04%
BM_Sort_string_Descending_1 4.23 4.89 115.60%
BM_Sort_string_Descending_4 11.8 13.2 111.86%
BM_Sort_string_Descending_16 25.3 26.4 104.35%
BM_Sort_string_Descending_64 29.7 30.7 103.37%
BM_Sort_string_Descending_256 27.3 29.6 108.42%
BM_Sort_string_Descending_1024 31.6 31.4 99.37%
BM_Sort_string_Descending_16384 46.5 47 101.08%
BM_Sort_string_Descending_262144 78.5 77.5 98.73%
BM_Sort_string_SingleElement_1 4.21 4.57 108.55%
BM_Sort_string_SingleElement_4 9.06 9.64 106.40%
BM_Sort_string_SingleElement_16 18.3 17.9 97.81%
BM_Sort_string_SingleElement_64 26.8 28.4 105.97%
BM_Sort_string_SingleElement_256 22.3 21.7 97.31%
BM_Sort_string_SingleElement_1024 19.5 20.1 103.08%
BM_Sort_string_SingleElement_16384 17.5 52.6 300.57%
BM_Sort_string_SingleElement_262144 19 48.2 253.68%
BM_Sort_string_PipeOrgan_1 4.18 6.79 162.44%
BM_Sort_string_PipeOrgan_4 10.3 14.1 136.89%
BM_Sort_string_PipeOrgan_16 25 29.7 118.80%
BM_Sort_string_PipeOrgan_64 37.5 39.2 104.53%
BM_Sort_string_PipeOrgan_256 45 45.7 101.56%
BM_Sort_string_PipeOrgan_1024 52.8 52.3 99.05%
BM_Sort_string_PipeOrgan_16384 72.4 138 190.61%
BM_Sort_string_PipeOrgan_262144 122 317 259.84%
BM_Sort_string_QuickSortAdversary_1 4.2 6.63 157.86%
BM_Sort_string_QuickSortAdversary_4 16.2 23 141.98%
BM_Sort_string_QuickSortAdversary_16 44.7 67.2 150.34%
BM_Sort_string_QuickSortAdversary_64 69.2 103 148.84%
BM_Sort_string_QuickSortAdversary_256 87.9 127 144.48%
BM_Sort_string_QuickSortAdversary_1024 106 157 148.11%
BM_Sort_string_QuickSortAdversary_16384 170 176 103.53%
BM_Sort_string_QuickSortAdversary_262144 269 263 97.77%
BM_Sort_float_Random_1 6.56 3.65 55.64%
BM_Sort_float_Random_4 15.1 4.92 32.58%
BM_Sort_float_Random_16 31.5 8.83 28.03%
BM_Sort_float_Random_64 51.7 15.4 29.79%
BM_Sort_float_Random_256 68.7 21.7 31.59%
BM_Sort_float_Random_1024 85.6 27.9 32.59%
BM_Sort_float_Random_16384 121 40 33.06%
BM_Sort_float_Random_262144 150 92 61.33%
BM_Sort_float_Ascending_1 6.6 11.4 172.73%
BM_Sort_float_Ascending_4 9.04 3.73 41.26%
BM_Sort_float_Ascending_16 3.71 2.82 76.01%
BM_Sort_float_Ascending_64 6.04 3.48 57.62%
BM_Sort_float_Ascending_256 4.99 2.86 57.31%
BM_Sort_float_Ascending_1024 4.74 2.24 47.26%
BM_Sort_float_Ascending_16384 4.59 1.85 40.31%
BM_Sort_float_Ascending_262144 4.58 1.64 35.81%
BM_Sort_float_Descending_1 6.54 5.87 89.76%
BM_Sort_float_Descending_4 9.03 2.34 25.91%
BM_Sort_float_Descending_16 37.8 5.22 13.81%
BM_Sort_float_Descending_64 11.5 2.77 24.09%
BM_Sort_float_Descending_256 10.3 2.65 25.73%
BM_Sort_float_Descending_1024 12.3 2.92 23.74%
BM_Sort_float_Descending_16384 11.8 2.65 22.46%
BM_Sort_float_Descending_262144 11.7 2.65 22.65%
BM_Sort_float_SingleElement_1 6.6 4.68 70.91%
BM_Sort_float_SingleElement_4 9 1.65 18.33%
BM_Sort_float_SingleElement_16 3.72 1.34 36.02%
BM_Sort_float_SingleElement_64 4.89 1.45 29.65%
BM_Sort_float_SingleElement_256 4.45 1.54 34.61%
BM_Sort_float_SingleElement_1024 4.42 1.41 31.90%
BM_Sort_float_SingleElement_16384 4.26 1.29 30.28%
BM_Sort_float_SingleElement_262144 4.26 1.31 30.75%
BM_Sort_float_PipeOrgan_1 6.88 5.76 83.72%
BM_Sort_float_PipeOrgan_4 9.05 1.5 16.57%
BM_Sort_float_PipeOrgan_16 12.4 1.92 15.48%
BM_Sort_float_PipeOrgan_64 38 3.96 10.42%
BM_Sort_float_PipeOrgan_256 15.8 2.39 15.13%
BM_Sort_float_PipeOrgan_1024 20.1 3.13 15.57%
BM_Sort_float_PipeOrgan_16384 25.1 3.52 14.02%
BM_Sort_float_PipeOrgan_262144 30.6 4.11 13.43%
BM_Sort_float_QuickSortAdversary_1 6.54 3.19 48.78%
BM_Sort_float_QuickSortAdversary_4 9.15 2.6 28.42%
BM_Sort_float_QuickSortAdversary_16 3.77 2.93 77.72%
BM_Sort_float_QuickSortAdversary_64 62.8 34.6 55.10%
BM_Sort_float_QuickSortAdversary_256 117 48.5 41.45%
BM_Sort_float_QuickSortAdversary_1024 177 121 68.36%
BM_Sort_float_QuickSortAdversary_16384 250 226 90.40%
BM_Sort_float_QuickSortAdversary_262144 307 249 81.11%
```
================
Comment at: libcxx/test/std/algorithms/alg.sorting/alg.sort/sort/ranges.sort.pass.cpp:18
+// constexpr I
+// sort(I first, S last, Comp comp = {}, Proj proj = {}); // since C++20
+//
----------------
philnik wrote:
> I don't think we're adding this to the synopsis in tests, but I don't really care either way.
FWIW, I usually do. I think copy-pasting is easiest (not just to write, but also to maintain) and there doesn't seem to be a strong reason to omit these annotations.
================
Comment at: libcxx/test/std/algorithms/alg.sorting/alg.sort/sort/ranges.sort.pass.cpp:41-46
+static_assert(HasSortIt<int*>);
+static_assert(!HasSortIt<RandomAccessIteratorNotDerivedFrom>);
+static_assert(!HasSortIt<RandomAccessIteratorBadIndex>);
+static_assert(!HasSortIt<int*, SentinelForNotSemiregular>);
+static_assert(!HasSortIt<int*, SentinelForNotWeaklyEqualityComparableWith>);
+static_assert(!HasSortIt<int*, int*, BadComparator>);
----------------
philnik wrote:
> I think you are missing SFINAE checks for `sortable`. I think it could be as simple as `static_assert(!HasSortIt<const int*>)` ditto for the range version.
Thanks!
================
Comment at: libcxx/test/std/algorithms/alg.sorting/alg.sort/sort/ranges.sort.pass.cpp:75
+
+ std::same_as<Iter> decltype(auto) last = std::ranges::sort(std::ranges::subrange(b, e));
+ assert(sorted == expected);
----------------
philnik wrote:
> This specifically checks with a borrowing range. I think I'd rather give it a lvalue-range and put the borrowing part into it's own test.
Do you have a specific approach in mind? I think `subrange` is a borrowing range regardless of whether it's an lvalue or an rvalue.
================
Comment at: libcxx/test/std/algorithms/alg.sorting/alg.sort/sort/ranges.sort.pass.cpp:161
+
+ constexpr bool operator==(S rhs) const { return i == rhs.i; }
+ };
----------------
philnik wrote:
> I //think// this should work. Same for you `A` struct above.
Thanks, it works (as long as it's a member function -- defining friend functions in local classes is apparently not allowed).
================
Comment at: libcxx/test/support/almost_satisfies_types.h:330-335
+ friend bool operator==(const Self&, const Self&);
+ friend bool operator!=(const Self&, const Self&);
+ friend bool operator< (const Self&, const Self&);
+ friend bool operator<=(const Self&, const Self&);
+ friend bool operator> (const Self&, const Self&);
+ friend bool operator>=(const Self&, const Self&);
----------------
philnik wrote:
> Couldn't you simply use `std::strong_ordering operator<=>(const Self&) const noexcept;`?
Thanks!
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D127557/new/
https://reviews.llvm.org/D127557
More information about the libcxx-commits
mailing list