bench: Add benchmark for prevector usage in std::vector

This commit is contained in:
Martin Leitner-Ankerl 2023-03-26 15:19:43 +02:00
parent e352f5ab6b
commit d380d2877e

View file

@ -80,6 +80,30 @@ static void PrevectorDeserialize(benchmark::Bench& bench)
});
}
template <typename T>
static void PrevectorFillVectorDirect(benchmark::Bench& bench)
{
bench.run([&] {
std::vector<prevector<28, T>> vec;
for (size_t i = 0; i < 260; ++i) {
vec.emplace_back();
}
});
}
template <typename T>
static void PrevectorFillVectorIndirect(benchmark::Bench& bench)
{
bench.run([&] {
std::vector<prevector<28, T>> vec;
for (size_t i = 0; i < 260; ++i) {
// force allocation
vec.emplace_back(29, T{});
}
});
}
#define PREVECTOR_TEST(name) \
static void Prevector##name##Nontrivial(benchmark::Bench& bench) \
{ \
@ -96,3 +120,5 @@ PREVECTOR_TEST(Clear)
PREVECTOR_TEST(Destructor)
PREVECTOR_TEST(Resize)
PREVECTOR_TEST(Deserialize)
PREVECTOR_TEST(FillVectorDirect)
PREVECTOR_TEST(FillVectorIndirect)