Skip to content

Commit

Permalink
Add benchmarks for FreeListAllocator.
Browse files Browse the repository at this point in the history
  • Loading branch information
ehpor committed Dec 6, 2024
1 parent 3804999 commit fa82ce3
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 0 deletions.
6 changes: 6 additions & 0 deletions benchmarks/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,13 @@ add_executable(timestamp timestamp.cpp)
target_include_directories(timestamp PUBLIC ../catkit_core)
target_link_libraries(timestamp PUBLIC catkit_core)

# Free list allocator benchmark
add_executable(free_list_allocator free_list_allocator.cpp)
target_include_directories(free_list_allocator PUBLIC ../catkit_core)
target_link_libraries(free_list_allocator PUBLIC catkit_core)

# Add install files
install(TARGETS datastream_latency DESTINATION bin)
install(TARGETS datastream_submit DESTINATION bin)
install(TARGETS timestamp DESTINATION bin)
install(TARGETS free_list_allocator DESTINATION bin)
91 changes: 91 additions & 0 deletions benchmarks/free_list_allocator.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
#include "FreeListAllocator.h"
#include "Timing.h"
#include <iostream>

void benchmark_linux_scalability()
{
typedef FreeListAllocator<16384, 32> Allocator;

const size_t N = 10000000;

auto *handles = new Allocator::BlockHandle[N];

Allocator allocator(size_t(32) * N);

auto start = GetTimeStamp();

for (size_t i = 0; i < N; ++i)
{
handles[i] = allocator.Allocate(16);
}

for (size_t i = 0; i < N; ++i)
{
allocator.Deallocate(handles[i]);
}

auto end = GetTimeStamp();

std::cout << "Linux Scalability:" << std::endl;
std::cout << "Time: " << (end - start) / 1e9 << " sec" << std::endl;
std::cout << "Throughput: " << 2 * N / ((end - start) / 1e9) << " ops/s" << std::endl;

delete[] handles;
}

void benchmark_larson()
{
const size_t ALIGNMENT = 32;
typedef FreeListAllocator<16384, ALIGNMENT> Allocator;

const size_t N = 10000000;
const size_t M = 1000;
const size_t MIN_SIZE = 16;
const size_t MAX_SIZE = 128;

auto *handles = new Allocator::BlockHandle[M];
for (size_t i = 0; i < M; ++i)
{
handles[i] = -1;
}

auto *indices = new size_t[N];
auto *sizes = new size_t[N];
for (size_t i = 0; i < N; ++i)
{
indices[i] = rand() % M;
sizes[i] = (MIN_SIZE + (rand() % (MAX_SIZE - MIN_SIZE))) * ALIGNMENT;
}

Allocator allocator(size_t(1024) * 1024 * 1024);

auto start = GetTimeStamp();

for (size_t i = 0; i < N; ++i)
{
size_t index = indices[i];
size_t size = sizes[i];

if (handles[index] != -1)
{
allocator.Deallocate(handles[index]);
}

handles[index] = allocator.Allocate(size);
}

auto end = GetTimeStamp();
std::cout << "Larson benchmark:" << std::endl;
std::cout << "Time: " << (end - start) / 1e9 << " sec" << std::endl;
std::cout << "Throughput: " << (N * 2 - M) / ((end - start) / 1e9) << " ops/s" << std::endl;

delete[] handles;
}

int main(int argc, char **argv)
{
benchmark_linux_scalability();
benchmark_larson();

return 0;
}

0 comments on commit fa82ce3

Please sign in to comment.