Skip to content

Commit

Permalink
Bench: better measurements of heaps performance
Browse files Browse the repository at this point in the history
  • Loading branch information
bersen66 committed May 6, 2024
1 parent f404dfd commit 7dc8f29
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 23 deletions.
17 changes: 16 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,19 @@ gtest_discover_tests(
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)
add_dependencies(lb_benchmark copy_configs)


set(VERSION_MAJOR 1)
set(VERSION_MINOR 0)
set(VERSION_PATCH 0)
# Установка путей к файлам
set(CPACK_PACKAGE_NAME ${PROJECT_NAME})
set(CPACK_PACKAGE_VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH})
set(CPACK_PACKAGE_DESCRIPTION "My application")
set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/DESCRIPTION.txt")
set(CPACK_PACKAGE_INSTALL_DIRECTORY "/usr/local")
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Your Name <your.email@example.com>")
set(CPACK_DEBIAN_PACKAGE_HOMEPAGE "https://example.com")
set(CPACK_DEBIAN_PACKAGE_PREDEPENDS "cmake")
set(CPACK_DEBIAN_PACKAGE_DEPENDS "liblb (>= 1.0.0)")
62 changes: 40 additions & 22 deletions benchmarks/benchmark_heaps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,38 +50,56 @@ static void BenchmarkPairingHeap(benchmark::State& state)

BENCHMARK(BenchmarkPairingHeap);

static void BenchmarkPairingHeapPush(benchmark::State& state)


template<typename HeapType>
void RunIncreaseDecreaseOperations(HeapType& heap,
std::vector<typename HeapType::handle_type>& handles)
{
for (int i = 0; i < handles.size(); ++i)
{
(*handles[i]).counter++;
heap.increase(handles[i]);
std::size_t num = (i + 10) % handles.size();
(*handles[num]).counter--;
heap.decrease(handles[num]);
}
}

static void BenchmarkFibID(benchmark::State& state)
{
boost::heap::pairing_heap<int> heap;
boost::heap::fibonacci_heap<CounterWrapper, boost::heap::compare<ConnectionsCompare>> heap;
using HandleType = boost::heap::fibonacci_heap<CounterWrapper, boost::heap::compare<ConnectionsCompare>>::handle_type;

std::vector<HandleType> handles;
for (std::size_t i = 0; i < 1000; ++i)
{
handles.push_back(heap.push(CounterWrapper{.b = nullptr, .counter = 0, .id = i}));
}

for (auto _ : state)
{
for (int i = 0; i < state.range(0); ++i)
{
heap.push(i);
}
while (!heap.empty())
{
heap.pop();
}
RunIncreaseDecreaseOperations(heap, handles);
}
}

BENCHMARK(BenchmarkPairingHeapPush)->Range(1<<0, 1<<16);
BENCHMARK(BenchmarkFibID);

static void BenchmarkFibonacciHeapPush(benchmark::State& state)
static void BenchmarkPairID(benchmark::State& state)
{
boost::heap::fibonacci_heap<int> heap;
boost::heap::pairing_heap<CounterWrapper, boost::heap::compare<ConnectionsCompare>> heap;
using HandleType = boost::heap::pairing_heap<CounterWrapper, boost::heap::compare<ConnectionsCompare>>::handle_type;

std::vector<HandleType> handles;
for (std::size_t i = 0; i < 1000; ++i)
{
handles.push_back(heap.push(CounterWrapper{.b = nullptr, .counter = 0, .id = i}));
}

for (auto _ : state)
{
for (int i = 0; i < state.range(0); ++i)
{
heap.push(i);
}
while (!heap.empty())
{
heap.pop();
}
RunIncreaseDecreaseOperations(heap, handles);
}
}

BENCHMARK(BenchmarkFibonacciHeapPush)->Range(1<<0, 1<<16);
BENCHMARK(BenchmarkPairID);

0 comments on commit 7dc8f29

Please sign in to comment.