diff options
author | Samuel Benzaquen <sbenza@google.com> | 2019-03-21 16:06:15 +0000 |
---|---|---|
committer | Samuel Benzaquen <sbenza@google.com> | 2019-03-21 16:06:15 +0000 |
commit | 9b7aa02b539fcf3856da8da9e2b89809da7935c9 (patch) | |
tree | a97012d96054a5f7eda2d60a4ffc4afc79a14bf0 /libcxx/benchmarks | |
parent | 7028cedafe01f18a71acfd34031820f7ad684350 (diff) | |
download | bcm5719-llvm-9b7aa02b539fcf3856da8da9e2b89809da7935c9.tar.gz bcm5719-llvm-9b7aa02b539fcf3856da8da9e2b89809da7935c9.zip |
Add relational benchmark against a string constant.
Summary:
Add relational benchmark against a string constant.
These can potentially trigger inlining of the operations. We want to
benchmark that.
Reviewers: EricWF
Subscribers: christof, jdoerfert, libcxx-commits
Tags: #libc
Differential Revision: https://reviews.llvm.org/D59512
llvm-svn: 356680
Diffstat (limited to 'libcxx/benchmarks')
-rw-r--r-- | libcxx/benchmarks/string.bench.cpp | 48 |
1 files changed, 44 insertions, 4 deletions
diff --git a/libcxx/benchmarks/string.bench.cpp b/libcxx/benchmarks/string.bench.cpp index b8f97e6e2c1..2d2b8a96091 100644 --- a/libcxx/benchmarks/string.bench.cpp +++ b/libcxx/benchmarks/string.bench.cpp @@ -73,16 +73,18 @@ struct AllDiffTypes : EnumValuesAsTuple<AllDiffTypes, DiffType, 4> { "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 @@ struct StringRelational { } }; +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 @@ int main(int argc, char** argv) { makeCartesianProductBenchmark<StringDestroy, AllLengths>(); makeCartesianProductBenchmark<StringRelational, AllRelations, AllLengths, AllLengths, AllDiffTypes>(); + makeCartesianProductBenchmark<StringRelationalLiteral, AllRelations, + AllLengths, AllDiffTypes>(); makeCartesianProductBenchmark<StringRead, AllTemperatures, AllDepths, AllLengths>(); benchmark::RunSpecifiedBenchmarks(); |