diff --git a/benchmarks/CMakeLists.txt b/benchmarks/CMakeLists.txt index 7bbce84d..a76ebf1e 100644 --- a/benchmarks/CMakeLists.txt +++ b/benchmarks/CMakeLists.txt @@ -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) diff --git a/benchmarks/hash_map.cpp b/benchmarks/hash_map.cpp new file mode 100644 index 00000000..60a75708 --- /dev/null +++ b/benchmarks/hash_map.cpp @@ -0,0 +1,50 @@ +#include "HashMap.h" +#include "Timing.h" + +#include + +int main(int argc, char **argv) +{ + typedef HashMap 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; +}