[libcxx-commits] [PATCH] D59512: Add relational benchmark against a string constant.
Samuel Benzaquen via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Thu Mar 21 09:05:09 PDT 2019
This revision was automatically updated to reflect the committed changes.
Closed by commit rCXX356680: Add relational benchmark against a string constant. (authored by sbenza, committed by ).
Herald added a subscriber: ldionne.
Changed prior to commit:
https://reviews.llvm.org/D59512?vs=191171&id=191714#toc
Repository:
rCXX libc++
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D59512/new/
https://reviews.llvm.org/D59512
Files:
benchmarks/string.bench.cpp
Index: benchmarks/string.bench.cpp
===================================================================
--- benchmarks/string.bench.cpp
+++ benchmarks/string.bench.cpp
@@ -73,16 +73,18 @@
"ChangeMiddle", "ChangeLast"};
};
+static constexpr char kSmallStringLiteral[] = "012345678";
+
TEST_ALWAYS_INLINE const char* getSmallString(DiffType D) {
switch (D) {
case DiffType::Control:
- return "0123456";
+ return kSmallStringLiteral;
case DiffType::ChangeFirst:
- return "-123456";
+ return "-12345678";
case DiffType::ChangeMiddle:
- return "012-456";
+ return "0123-5678";
case DiffType::ChangeLast:
- return "012345-";
+ return "01234567-";
}
}
@@ -261,6 +263,42 @@
}
};
+template <class Rel, class LHLength, class DiffType>
+struct StringRelationalLiteral {
+ static void run(benchmark::State& state) {
+ auto Lhs = makeString(LHLength(), DiffType());
+ for (auto _ : state) {
+ benchmark::DoNotOptimize(Lhs);
+ switch (Rel()) {
+ case Relation::Eq:
+ benchmark::DoNotOptimize(Lhs == kSmallStringLiteral);
+ break;
+ case Relation::Less:
+ benchmark::DoNotOptimize(Lhs < kSmallStringLiteral);
+ break;
+ case Relation::Compare:
+ benchmark::DoNotOptimize(Lhs.compare(kSmallStringLiteral));
+ break;
+ }
+ }
+ }
+
+ static bool skip() {
+ // Doesn't matter how they differ if they have different size.
+ if (LHLength() != Length::Small && DiffType() != ::DiffType::Control)
+ return true;
+ // We don't need huge. Doensn't give anything different than Large.
+ if (LHLength() == Length::Huge)
+ return true;
+ return false;
+ }
+
+ static std::string name() {
+ return "BM_StringRelationalLiteral" + Rel::name() + LHLength::name() +
+ DiffType::name();
+ }
+};
+
enum class Depth { Shallow, Deep };
struct AllDepths : EnumValuesAsTuple<AllDepths, Depth, 2> {
static constexpr const char* Names[] = {"Shallow", "Deep"};
@@ -369,6 +407,8 @@
makeCartesianProductBenchmark<StringDestroy, AllLengths>();
makeCartesianProductBenchmark<StringRelational, AllRelations, AllLengths,
AllLengths, AllDiffTypes>();
+ makeCartesianProductBenchmark<StringRelationalLiteral, AllRelations,
+ AllLengths, AllDiffTypes>();
makeCartesianProductBenchmark<StringRead, AllTemperatures, AllDepths,
AllLengths>();
benchmark::RunSpecifiedBenchmarks();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D59512.191714.patch
Type: text/x-patch
Size: 2587 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20190321/5def5b2f/attachment.bin>
More information about the libcxx-commits
mailing list