Skip to content

Commit

Permalink
Add another 2
Browse files Browse the repository at this point in the history
  • Loading branch information
mingxwa committed Oct 7, 2024
1 parent bfd095c commit 96d24d3
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions benchmarks/proxy_management_benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ struct LargeObject3 {
void* Padding[15];
};

struct PolymorphicObjectBase {
virtual ~PolymorphicObjectBase() = default;
};
template <class T>
struct PolymorphicObject : PolymorphicObjectBase {
T Value;
};

} // namespace

struct DefaultFacade : pro::facade_builder
Expand All @@ -59,6 +67,26 @@ void BM_SmallObjectManagementWithProxy(benchmark::State& state) {
}
}

void BM_SmallObjectManagementWithUniquePtr(benchmark::State& state) {
for (auto _ : state) {
std::vector<std::unique_ptr<PolymorphicObjectBase>> data;
data.reserve(TestManagedObjectCount);
for (int i = 0; i < TestManagedObjectCount; i += TypeSeriesCount) {
std::unique_ptr<PolymorphicObjectBase> p1{new PolymorphicObject<SmallObject1>()};
std::unique_ptr<PolymorphicObjectBase> p2{new PolymorphicObject<SmallObject2>()};
std::unique_ptr<PolymorphicObjectBase> p3{new PolymorphicObject<SmallObject3>()};

benchmark::DoNotOptimize(p1);
benchmark::DoNotOptimize(p2);
benchmark::DoNotOptimize(p3);

data.push_back(std::move(p1));
data.push_back(std::move(p2));
data.push_back(std::move(p3));
}
}
}

void BM_SmallObjectManagementWithSharedPtr(benchmark::State& state) {
for (auto _ : state) {
std::vector<std::shared_ptr<void>> data;
Expand Down Expand Up @@ -163,6 +191,26 @@ void BM_LargeObjectManagementWithProxy_Pooled(benchmark::State& state) {
}
}

void BM_LargeObjectManagementWithUniquePtr(benchmark::State& state) {
for (auto _ : state) {
std::vector<std::unique_ptr<PolymorphicObjectBase>> data;
data.reserve(TestManagedObjectCount);
for (int i = 0; i < TestManagedObjectCount; i += TypeSeriesCount) {
std::unique_ptr<PolymorphicObjectBase> p1{new PolymorphicObject<LargeObject1>()};
std::unique_ptr<PolymorphicObjectBase> p2{new PolymorphicObject<LargeObject2>()};
std::unique_ptr<PolymorphicObjectBase> p3{new PolymorphicObject<LargeObject3>()};

benchmark::DoNotOptimize(p1);
benchmark::DoNotOptimize(p2);
benchmark::DoNotOptimize(p3);

data.push_back(std::move(p1));
data.push_back(std::move(p2));
data.push_back(std::move(p3));
}
}
}

void BM_LargeObjectManagementWithSharedPtr(benchmark::State& state) {
for (auto _ : state) {
std::vector<std::shared_ptr<void>> data;
Expand Down Expand Up @@ -230,11 +278,13 @@ void BM_LargeObjectManagementWithAny(benchmark::State& state) {
}

BENCHMARK(BM_SmallObjectManagementWithProxy);
BENCHMARK(BM_SmallObjectManagementWithUniquePtr);
BENCHMARK(BM_SmallObjectManagementWithSharedPtr);
BENCHMARK(BM_SmallObjectManagementWithSharedPtr_Pooled);
BENCHMARK(BM_SmallObjectManagementWithAny);
BENCHMARK(BM_LargeObjectManagementWithProxy);
BENCHMARK(BM_LargeObjectManagementWithProxy_Pooled);
BENCHMARK(BM_LargeObjectManagementWithUniquePtr);
BENCHMARK(BM_LargeObjectManagementWithSharedPtr);
BENCHMARK(BM_LargeObjectManagementWithSharedPtr_Pooled);
BENCHMARK(BM_LargeObjectManagementWithAny);

0 comments on commit 96d24d3

Please sign in to comment.