[libcxx-commits] [libcxx] [libc++] Optimize std::min_element (PR #100616)

via libcxx-commits libcxx-commits at lists.llvm.org
Thu Jul 25 11:04:45 PDT 2024


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff f1b76c53b6312a10d2ee4219e980498e7cbe5d53 cb48c93356fef4b0197e168daff220702c3e74c0 --extensions h,cpp -- libcxx/benchmarks/min_element.bench.cpp libcxx/include/__algorithm/min_element.h
``````````

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/libcxx/benchmarks/min_element.bench.cpp b/libcxx/benchmarks/min_element.bench.cpp
index ed769aeeea..7edb8ddbb1 100644
--- a/libcxx/benchmarks/min_element.bench.cpp
+++ b/libcxx/benchmarks/min_element.bench.cpp
@@ -1,48 +1,80 @@
-#include <vector>
 #include <algorithm>
 #include <limits>
+#include <vector>
 
 #include <benchmark/benchmark.h>
 #include <random>
 
-template<typename T>
-static void BM_stdmin_element_decreasing(benchmark::State &state){
-    std::vector<T> v(state.range(0));
-    T start = std::numeric_limits<T>::max();
-    T end = std::numeric_limits<T>::min();
+template <typename T>
+static void BM_stdmin_element_decreasing(benchmark::State& state) {
+  std::vector<T> v(state.range(0));
+  T start = std::numeric_limits<T>::max();
+  T end   = std::numeric_limits<T>::min();
 
-    for(size_t i = 0; i < v.size(); i++)
-        v[i] = ((start != end) ? start-- : end);
+  for (size_t i = 0; i < v.size(); i++)
+    v[i] = ((start != end) ? start-- : end);
 
-    for(auto _ : state){
-        benchmark::DoNotOptimize(v);
-        benchmark::DoNotOptimize(std::min_element(v.begin(), v.end()));
-    }
+  for (auto _ : state) {
+    benchmark::DoNotOptimize(v);
+    benchmark::DoNotOptimize(std::min_element(v.begin(), v.end()));
+  }
 }
 
 BENCHMARK(BM_stdmin_element_decreasing<char>)
-    ->DenseRange(1, 8)->Range(32, 128)->Range(256, 4096)->DenseRange(5000, 10000, 1000)
-    ->Range(1<<14, 1<<16)->Arg(70000);
+    ->DenseRange(1, 8)
+    ->Range(32, 128)
+    ->Range(256, 4096)
+    ->DenseRange(5000, 10000, 1000)
+    ->Range(1 << 14, 1 << 16)
+    ->Arg(70000);
 BENCHMARK(BM_stdmin_element_decreasing<short>)
-    ->DenseRange(1, 8)->Range(32, 128)->Range(256, 4096)->DenseRange(5000, 10000, 1000)
-    ->Range(1<<14, 1<<16)->Arg(70000);
+    ->DenseRange(1, 8)
+    ->Range(32, 128)
+    ->Range(256, 4096)
+    ->DenseRange(5000, 10000, 1000)
+    ->Range(1 << 14, 1 << 16)
+    ->Arg(70000);
 BENCHMARK(BM_stdmin_element_decreasing<int>)
-    ->DenseRange(1, 8)->Range(32, 128)->Range(256, 4096)->DenseRange(5000, 10000, 1000)
-    ->Range(1<<14, 1<<16)->Arg(70000);
+    ->DenseRange(1, 8)
+    ->Range(32, 128)
+    ->Range(256, 4096)
+    ->DenseRange(5000, 10000, 1000)
+    ->Range(1 << 14, 1 << 16)
+    ->Arg(70000);
 BENCHMARK(BM_stdmin_element_decreasing<long long>)
-    ->DenseRange(1, 8)->Range(32, 128)->Range(256, 4096)->DenseRange(5000, 10000, 1000)
-    ->Range(1<<14, 1<<16)->Arg(70000);
+    ->DenseRange(1, 8)
+    ->Range(32, 128)
+    ->Range(256, 4096)
+    ->DenseRange(5000, 10000, 1000)
+    ->Range(1 << 14, 1 << 16)
+    ->Arg(70000);
 BENCHMARK(BM_stdmin_element_decreasing<unsigned char>)
-    ->DenseRange(1, 8)->Range(32, 128)->Range(256, 4096)->DenseRange(5000, 10000, 1000)
-    ->Range(1<<14, 1<<16)->Arg(70000);
+    ->DenseRange(1, 8)
+    ->Range(32, 128)
+    ->Range(256, 4096)
+    ->DenseRange(5000, 10000, 1000)
+    ->Range(1 << 14, 1 << 16)
+    ->Arg(70000);
 BENCHMARK(BM_stdmin_element_decreasing<unsigned short>)
-    ->DenseRange(1, 8)->Range(32, 128)->Range(256, 4096)->DenseRange(5000, 10000, 1000)
-    ->Range(1<<14, 1<<16)->Arg(70000);
+    ->DenseRange(1, 8)
+    ->Range(32, 128)
+    ->Range(256, 4096)
+    ->DenseRange(5000, 10000, 1000)
+    ->Range(1 << 14, 1 << 16)
+    ->Arg(70000);
 BENCHMARK(BM_stdmin_element_decreasing<unsigned int>)
-    ->DenseRange(1, 8)->Range(32, 128)->Range(256, 4096)->DenseRange(5000, 10000, 1000)
-    ->Range(1<<14, 1<<16)->Arg(70000);
+    ->DenseRange(1, 8)
+    ->Range(32, 128)
+    ->Range(256, 4096)
+    ->DenseRange(5000, 10000, 1000)
+    ->Range(1 << 14, 1 << 16)
+    ->Arg(70000);
 BENCHMARK(BM_stdmin_element_decreasing<unsigned long long>)
-    ->DenseRange(1, 8)->Range(32, 128)->Range(256, 4096)->DenseRange(5000, 10000, 1000)
-    ->Range(1<<14, 1<<16)->Arg(70000);
+    ->DenseRange(1, 8)
+    ->Range(32, 128)
+    ->Range(256, 4096)
+    ->DenseRange(5000, 10000, 1000)
+    ->Range(1 << 14, 1 << 16)
+    ->Arg(70000);
 
 BENCHMARK_MAIN();

``````````

</details>


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


More information about the libcxx-commits mailing list