Skip to content

Commit

Permalink
Feat: added benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
bersen66 committed May 1, 2024
1 parent 8f26073 commit 63c83bd
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 1 deletion.
5 changes: 4 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,13 @@ target_link_libraries(
yaml-cpp::yaml-cpp
jemalloc::jemalloc
)

add_dependencies(lb_tests copy_configs)
gtest_discover_tests(
lb_tests
WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
)

file(GLOB lb_benchmark_sources benchmarks/*.cpp)
add_executable(lb_benchmark ${lb_benchmark_sources})
target_link_libraries(lb_benchmark PUBLIC lb2 benchmark::benchmark_main)
add_dependencies(lb_benchmark copy_configs)
49 changes: 49 additions & 0 deletions benchmarks/benchmark_heaps.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#include <benchmark/benchmark.h>
#include <boost/heap/fibonacci_heap.hpp>
#include <lb/tcp/selectors.hpp>


struct CounterWrapper {
lb::tcp::Backend* b;
std::size_t counter = 0;
std::size_t id = 0;
};

struct ConnectionsCompare {
bool operator()(const CounterWrapper& lhs, const CounterWrapper& rhs) const
{
return lhs.counter > rhs.counter;
}
};

static void BenchmarkFibbanaciHeap(benchmark::State& state)
{
for (auto _ : state)
{
boost::heap::fibonacci_heap<CounterWrapper, boost::heap::compare<ConnectionsCompare>> heap;
auto handle1 = heap.push({nullptr, 0, 1});
auto handle2 = heap.push({nullptr, 0, 2});
(*handle1).counter++;
heap.increase(handle1);
heap.erase(handle2);
heap.erase(handle1);
}
}

BENCHMARK(BenchmarkFibbanaciHeap);

static void BenchmarkPairingHeap(benchmark::State& state)
{
for (auto _ : state)
{
boost::heap::pairing_heap<CounterWrapper, boost::heap::compare<ConnectionsCompare>> heap;
auto handle1 = heap.push({nullptr, 0, 1});
auto handle2 = heap.push({nullptr, 0, 2});
(*handle1).counter++;
heap.increase(handle1);
heap.erase(handle2);
heap.erase(handle1);
}
}

BENCHMARK(BenchmarkPairingHeap);
1 change: 1 addition & 0 deletions cmake/install_dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ find_package(spdlog REQUIRED)
find_package(jemalloc REQUIRED)
find_package(GTest REQUIRED)
find_package(ctre REQUIRED)
find_package(benchmark REQUIRED)

include_directories(${Boost_INCLUDE_DIRS})
include_directories(${yaml-cpp_INCLUDE_DIRS})
Expand Down
1 change: 1 addition & 0 deletions conanfile.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ spdlog/1.13.0
jemalloc/5.3.0
ctre/3.8.1
gtest/1.14.0
benchmark/1.8.3

[generators]
CMakeDeps
Expand Down

0 comments on commit 63c83bd

Please sign in to comment.