[libcxx-commits] [libcxx] 51ccdfe - [libc++] Add benchmark for string::pop_back() (#223729)

via libcxx-commits libcxx-commits at lists.llvm.org
Fri Sep 25 10:59:26 PDT 2026


Author: Nikolas Klauser
Date: 2026-09-25T19:59:19+02:00
New Revision: 51ccdfeadcfe29b1d46f978e8582ada109aebb91

URL: https://github.com/llvm/llvm-project/commit/51ccdfeadcfe29b1d46f978e8582ada109aebb91
DIFF: https://github.com/llvm/llvm-project/commit/51ccdfeadcfe29b1d46f978e8582ada109aebb91.diff

LOG: [libc++] Add benchmark for string::pop_back() (#223729)

Added: 
    

Modified: 
    libcxx/test/benchmarks/containers/string.bench.cpp

Removed: 
    


################################################################################
diff  --git a/libcxx/test/benchmarks/containers/string.bench.cpp b/libcxx/test/benchmarks/containers/string.bench.cpp
index aaf8f69df37b4..48004e966129f 100644
--- a/libcxx/test/benchmarks/containers/string.bench.cpp
+++ b/libcxx/test/benchmarks/containers/string.bench.cpp
@@ -264,6 +264,33 @@ int main(int argc, char** argv) {
           [](auto bm) { bm->Arg(small_size)->Arg(large_size); });
   }
 
+  {
+    static auto bench_impl =
+        []<bool opaque, class CharT>(std::bool_constant<opaque>, std::type_identity<CharT>, benchmark::State& state) {
+          std::basic_string<CharT> strings[4096];
+
+          size_t size = state.range();
+          size_t pos  = size / 2;
+          while (state.KeepRunningBatch(std::size(strings))) {
+            state.PauseTiming();
+            for (auto& string : strings)
+              string.resize(size, 'a');
+            state.ResumeTiming();
+            for (auto& string : strings) {
+              if constexpr (opaque)
+                benchmark::DoNotOptimize(pos);
+              string.pop_back();
+            }
+          }
+        };
+    bench("std::basic_string::pop_back() (opaque)", std::bind_front(bench_impl, std::true_type{}), [](auto bm) {
+      bm->Arg(small_size)->Arg(large_size);
+    });
+    bench("std::basic_string::pop_back() (transparent)", std::bind_front(bench_impl, std::false_type{}), [](auto bm) {
+      bm->Arg(small_size)->Arg(large_size);
+    });
+  }
+
   // [string.ops]
   bench("std::basic_string::data()", []<class CharT>(std::type_identity<CharT>, benchmark::State& state) {
     std::basic_string<CharT> str;


        


More information about the libcxx-commits mailing list