Skip to content

Conversation

philnik777
Copy link
Contributor

----------------------------------------------------------
Benchmark                                 old          new
----------------------------------------------------------
BM_std_rotate<int>/1                 0.707 ns      2.83 ns
BM_std_rotate<int>/2                 0.706 ns      2.83 ns
BM_std_rotate<int>/3                  4.93 ns      5.04 ns
BM_std_rotate<int>/4                  5.12 ns      5.14 ns
BM_std_rotate<int>/32                 41.3 ns      16.5 ns
BM_std_rotate<int>/64                 94.1 ns      42.8 ns
BM_std_rotate<int>/512                 764 ns       194 ns
BM_std_rotate<int>/4096               5899 ns      2687 ns
BM_std_rotate<int>/65536             94248 ns     43003 ns
BM_std_rotate<__int128>/1            0.713 ns      2.16 ns
BM_std_rotate<__int128>/2            0.711 ns      2.16 ns
BM_std_rotate<__int128>/3             5.63 ns      5.70 ns
BM_std_rotate<__int128>/4             5.64 ns      5.62 ns
BM_std_rotate<__int128>/32            46.1 ns      29.8 ns
BM_std_rotate<__int128>/64            98.6 ns      75.6 ns
BM_std_rotate<__int128>/512            752 ns       486 ns
BM_std_rotate<__int128>/4096          5849 ns      4913 ns
BM_std_rotate<__int128>/65536        97091 ns     78037 ns
BM_std_rotate<std::string>/1         0.722 ns     0.717 ns
BM_std_rotate<std::string>/2         0.722 ns     0.718 ns
BM_std_rotate<std::string>/3          4.35 ns      4.42 ns
BM_std_rotate<std::string>/4          6.12 ns      6.08 ns
BM_std_rotate<std::string>/32         46.7 ns      46.4 ns
BM_std_rotate<std::string>/64         95.7 ns      94.9 ns
BM_std_rotate<std::string>/512         795 ns       792 ns
BM_std_rotate<std::string>/4096       6500 ns      6442 ns
BM_std_rotate<std::string>/65536    106532 ns    103567 ns

Fixes #54949
Fixes #39644

Copy link

⚠️ C/C++ code formatter, clang-format found issues in your code. ⚠️

You can test this locally with the following command:
git-clang-format --diff fd784726db70a5155594c32ee839b8807fafd87d 6399aec8e1b59b0aa436cf5e08ac78cdb18bd3d3 --extensions cpp,h -- libcxx/test/benchmarks/algorithms/rotate.bench.cpp libcxx/include/__algorithm/rotate.h
View the diff from clang-format here.
diff --git a/libcxx/include/__algorithm/rotate.h b/libcxx/include/__algorithm/rotate.h
index 1755a75888..91a073c1be 100644
--- a/libcxx/include/__algorithm/rotate.h
+++ b/libcxx/include/__algorithm/rotate.h
@@ -84,9 +84,9 @@ __rotate_forward(_ForwardIterator __first, _ForwardIterator __middle, _ForwardIt
 
 template <class _AlgPolicy, class _Iter, class _Sent>
 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 _Iter __rotate_random(_Iter __first, _Iter __middle, _Sent __last) {
-  auto __left = _IterOps<_AlgPolicy>::distance(__first, __middle);
+  auto __left  = _IterOps<_AlgPolicy>::distance(__first, __middle);
   auto __right = _IterOps<_AlgPolicy>::distance(__middle, __last);
-  auto __end = __first + __right;
+  auto __end   = __first + __right;
 
   if (__left == 0 || __first == __last)
     return __first;

@ldionne
Copy link
Member

ldionne commented Jan 9, 2025

@philnik777 Why was this closed?

@philnik777
Copy link
Contributor Author

@philnik777 Why was this closed?

Because I've accidentally used the main branch of my fork. The new PR is #120890. Sorry for not mentioning it before.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[libcxx] std::rotate gcd is 3-10x slower than the forward variant. Benchmarking std::rotate.

2 participants