[libcxx-commits] [PATCH] D73740: Add benchmarks for basic_string::erase
Martijn Vels via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Feb 19 14:11:01 PST 2020
This revision was automatically updated to reflect the committed changes.
Closed by commit rGc4b8c3ddc1ab: Add benchmarks for basic_string::erase (authored by mvels).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D73740/new/
https://reviews.llvm.org/D73740
Files:
libcxx/benchmarks/string.bench.cpp
Index: libcxx/benchmarks/string.bench.cpp
===================================================================
--- libcxx/benchmarks/string.bench.cpp
+++ libcxx/benchmarks/string.bench.cpp
@@ -308,6 +308,58 @@
}
};
+template <class Length, class Opaque>
+struct StringEraseToEnd {
+ static void run(benchmark::State& state) {
+ constexpr bool opaque = Opaque{} == Opacity::Opaque;
+ constexpr int kNumStrings = 4 << 10;
+ std::string strings[kNumStrings];
+ const int mid = makeString(Length()).size() / 2;
+ while (state.KeepRunningBatch(kNumStrings)) {
+ state.PauseTiming();
+ for (int i = 0; i < kNumStrings; ++i) {
+ strings[i] = makeString(Length());
+ }
+ benchmark::DoNotOptimize(strings);
+ state.ResumeTiming();
+ for (int i = 0; i < kNumStrings; ++i) {
+ strings[i].erase(maybeOpaque(mid, opaque),
+ maybeOpaque(std::string::npos, opaque));
+ }
+ }
+ }
+
+ static std::string name() {
+ return "BM_StringEraseToEnd" + Length::name() + Opaque::name();
+ }
+};
+
+template <class Length, class Opaque>
+struct StringEraseWithMove {
+ static void run(benchmark::State& state) {
+ constexpr bool opaque = Opaque{} == Opacity::Opaque;
+ constexpr int kNumStrings = 4 << 10;
+ std::string strings[kNumStrings];
+ const int n = makeString(Length()).size() / 2;
+ const int pos = n / 2;
+ while (state.KeepRunningBatch(kNumStrings)) {
+ state.PauseTiming();
+ for (int i = 0; i < kNumStrings; ++i) {
+ strings[i] = makeString(Length());
+ }
+ benchmark::DoNotOptimize(strings);
+ state.ResumeTiming();
+ for (int i = 0; i < kNumStrings; ++i) {
+ strings[i].erase(maybeOpaque(pos, opaque), maybeOpaque(n, opaque));
+ }
+ }
+ }
+
+ static std::string name() {
+ return "BM_StringEraseWithMove" + Length::name() + Opaque::name();
+ }
+};
+
template <class Opaque>
struct StringAssignAsciizMix {
static void run(benchmark::State& state) {
@@ -556,6 +608,8 @@
makeCartesianProductBenchmark<StringDestroy, AllLengths>();
makeCartesianProductBenchmark<StringResizeDefaultInit, AllLengths,
AllOpacity>();
+ makeCartesianProductBenchmark<StringEraseToEnd, AllLengths, AllOpacity>();
+ makeCartesianProductBenchmark<StringEraseWithMove, AllLengths, AllOpacity>();
makeCartesianProductBenchmark<StringRelational, AllRelations, AllLengths,
AllLengths, AllDiffTypes>();
makeCartesianProductBenchmark<StringRelationalLiteral, AllRelations,
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D73740.245522.patch
Type: text/x-patch
Size: 2594 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20200219/41f2e77e/attachment.bin>
More information about the libcxx-commits
mailing list