- d6b8d35be9659e1c99a5daca1af8c8587acaa044 Update bazel_toolchains to the latest commit. by Abseil Team <absl-team@google.com>
- 38311bf46f29bf1b20bdfe6c9b10c54e6258d28c Fix inlined_vector_benchmark when using libc++. libc++'s ... by Derek Mauro <dmauro@google.com> - 32178d067d4af7c3062532103d213eb7230c2be6 Adding sha256 hashes to dependencies in Abseil OSS WORKSP... by Daniel Katz <katzdm@google.com> - 13ac34416b326909f1ce0889ec0eb3bff3f3bebe Fix silly whitespace typo. by Daniel Katz <katzdm@google.com> GitOrigin-RevId: d6b8d35be9659e1c99a5daca1af8c8587acaa044 Change-Id: I6be0d76930206edb79a10779bff3ffcc5ce856c9
This commit is contained in:
parent
eb686c069f
commit
f44e1eed08
3 changed files with 36 additions and 22 deletions
|
@ -63,18 +63,34 @@ void BM_StdVectorFill(benchmark::State& state) {
|
|||
}
|
||||
BENCHMARK(BM_StdVectorFill)->Range(0, 1024);
|
||||
|
||||
// The purpose of the next two benchmarks is to verify that
|
||||
// absl::InlinedVector is efficient when moving is more efficent than
|
||||
// copying. To do so, we use strings that are larger than the short
|
||||
// std::string optimization.
|
||||
bool StringRepresentedInline(std::string s) {
|
||||
const char* chars = s.data();
|
||||
std::string s1 = std::move(s);
|
||||
return s1.data() != chars;
|
||||
}
|
||||
|
||||
int GetNonShortStringOptimizationSize() {
|
||||
for (int i = 24; i <= 192; i *= 2) {
|
||||
if (!StringRepresentedInline(std::string(i, 'A'))) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
ABSL_RAW_LOG(
|
||||
FATAL,
|
||||
"Failed to find a std::string larger than the short std::string optimization");
|
||||
return -1;
|
||||
}
|
||||
|
||||
void BM_InlinedVectorFillString(benchmark::State& state) {
|
||||
const int len = state.range(0);
|
||||
std::string strings[4] = {"a quite long string",
|
||||
"another long string",
|
||||
"012345678901234567",
|
||||
"to cause allocation"};
|
||||
const int no_sso = GetNonShortStringOptimizationSize();
|
||||
std::string strings[4] = {std::string(no_sso, 'A'), std::string(no_sso, 'B'),
|
||||
std::string(no_sso, 'C'), std::string(no_sso, 'D')};
|
||||
|
||||
for (auto _ : state) {
|
||||
absl::InlinedVector<std::string, 8> v;
|
||||
for (int i = 0; i < len; i++) {
|
||||
|
@ -87,10 +103,10 @@ BENCHMARK(BM_InlinedVectorFillString)->Range(0, 1024);
|
|||
|
||||
void BM_StdVectorFillString(benchmark::State& state) {
|
||||
const int len = state.range(0);
|
||||
std::string strings[4] = {"a quite long string",
|
||||
"another long string",
|
||||
"012345678901234567",
|
||||
"to cause allocation"};
|
||||
const int no_sso = GetNonShortStringOptimizationSize();
|
||||
std::string strings[4] = {std::string(no_sso, 'A'), std::string(no_sso, 'B'),
|
||||
std::string(no_sso, 'C'), std::string(no_sso, 'D')};
|
||||
|
||||
for (auto _ : state) {
|
||||
std::vector<std::string> v;
|
||||
for (int i = 0; i < len; i++) {
|
||||
|
@ -98,11 +114,6 @@ void BM_StdVectorFillString(benchmark::State& state) {
|
|||
}
|
||||
}
|
||||
state.SetItemsProcessed(static_cast<int64_t>(state.iterations()) * len);
|
||||
// The purpose of the benchmark is to verify that inlined vector is
|
||||
// efficient when moving is more efficent than copying. To do so, we
|
||||
// use strings that are larger than the small std::string optimization.
|
||||
ABSL_RAW_CHECK(!StringRepresentedInline(strings[0]),
|
||||
"benchmarked with strings that are too small");
|
||||
}
|
||||
BENCHMARK(BM_StdVectorFillString)->Range(0, 1024);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue