Skip to content

Commit

Permalink
Add benchmark for hash map.
Browse files Browse the repository at this point in the history
  • Loading branch information
ehpor committed Dec 12, 2024
1 parent 3f630cb commit 66a95a0
Show file tree
Hide file tree
Showing 2 changed files with 56 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 @@ -34,9 +34,15 @@ add_executable(pool_allocator pool_allocator.cpp)
target_include_directories(pool_allocator PUBLIC ../catkit_core)
target_link_libraries(pool_allocator PUBLIC catkit_core)

# Hash map benchmark
add_executable(hash_map hash_map.cpp)
target_include_directories(hash_map PUBLIC ../catkit_core)
target_link_libraries(hash_map 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)
install(TARGETS pool_allocator DESTINATION bin)
install(TARGETS hash_map DESTINATION bin)
50 changes: 50 additions & 0 deletions benchmarks/hash_map.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#include "HashMap.h"
#include "Timing.h"

#include <iostream>

int main(int argc, char **argv)
{
typedef HashMap<int, 16384, 32> MyHashMap;

std::size_t buffer_size = MyHashMap::CalculateBufferSize();
char *buffer = new char[buffer_size];

MyHashMap map(buffer);
map.Initialize();

std::uint64_t total_time = 0;
std::size_t N = 1000;

for (size_t i = 0; i < N; ++i)
{
std::string key = "key" + std::to_string(i);

auto start = GetTimeStamp();
map.Insert(key, i);
auto end = GetTimeStamp();

total_time += end - start;
}

std::cout << "Insertion time: " << total_time / N << " ns" << std::endl;

total_time = 0;

for (size_t i = 0; i < N; ++i)
{
std::string key = "key" + std::to_string(i);

auto start = GetTimeStamp();
const int *value = map.Find(key);
auto end = GetTimeStamp();

total_time += end - start;
}

std::cout << "Lookup time: " << total_time / N << " ns" << std::endl;

delete[] buffer;

return 0;
}

0 comments on commit 66a95a0

Please sign in to comment.