Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 3 additions & 13 deletions benchmark/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
add_executable(compilation_benchmark EXCLUDE_FROM_ALL big_nexus.cpp)

target_compile_options(
compilation_benchmark
PRIVATE -ftemplate-backtrace-limit=0
$<$<CXX_COMPILER_ID:Clang>:-fconstexpr-steps=2000000>
$<$<CXX_COMPILER_ID:Clang>:-fbracket-depth=512>
$<$<CXX_COMPILER_ID:Clang>:-ferror-limit=8>
$<$<CXX_COMPILER_ID:GNU>:-fmax-errors=8>)

target_link_libraries(compilation_benchmark PRIVATE cib profile-compilation)
target_include_directories(compilation_benchmark
PRIVATE ${CMAKE_SOURCE_DIR}/test/)
add_subdirectory(cib)
add_subdirectory(lookup)
add_subdirectory(msg)
13 changes: 13 additions & 0 deletions benchmark/cib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
add_executable(compilation_benchmark EXCLUDE_FROM_ALL big_nexus.cpp)

target_compile_options(
compilation_benchmark
PRIVATE -ftemplate-backtrace-limit=0
$<$<CXX_COMPILER_ID:Clang>:-fconstexpr-steps=2000000>
$<$<CXX_COMPILER_ID:Clang>:-fbracket-depth=512>
$<$<CXX_COMPILER_ID:Clang>:-ferror-limit=8>
$<$<CXX_COMPILER_ID:GNU>:-fmax-errors=8>)

target_link_libraries(compilation_benchmark PRIVATE cib profile-compilation)
target_include_directories(compilation_benchmark
PRIVATE ${CMAKE_SOURCE_DIR}/test/)
File renamed without changes.
113 changes: 113 additions & 0 deletions benchmark/lookup/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
add_versioned_package("gh:boost-ext/mph#v1.0.8")
add_versioned_package("gh:serge-sans-paille/frozen#292a811")

function(gen_lookup_data)
set(oneValueArgs TARGET TYPE SIZE OUTPUT)
cmake_parse_arguments(GEN "" "${oneValueArgs}" "" ${ARGN})

set(script "${CMAKE_SOURCE_DIR}/tools/benchmark/gen_map_data.py")
get_filename_component(DIR "${GEN_OUTPUT}" DIRECTORY)

add_custom_command(
OUTPUT ${GEN_OUTPUT}
COMMAND ${CMAKE_COMMAND} -E make_directory "${DIR}"
COMMAND ${Python3_EXECUTABLE} ${script} --type ${GEN_TYPE} --size
${GEN_SIZE} --output ${GEN_OUTPUT}
DEPENDS ${script}
COMMAND_EXPAND_LISTS)
add_custom_target(${GEN_TARGET} DEPENDS ${GEN_OUTPUT})
endfunction()

set(ALG_NAMES
std_map
std_unordered_map
frozen_map
frozen_unordered_map
pseudo_pext_direct
pseudo_pext_indirect_1
pseudo_pext_indirect_2
pseudo_pext_indirect_3
pseudo_pext_indirect_4
pseudo_pext_indirect_5
pseudo_pext_indirect_6)

set(EXCLUDED_COMBINATIONS
mph_pext_exp_uint32_70
mph_pext_exp_uint32_80
mph_pext_exp_uint32_90
mph_pext_exp_uint32_100
mph_pext_exp_uint32_200
mph_pext_exp_uint32_300
mph_pext_exp_uint32_400
mph_pext_exp_uint32_500
mph_pext_exp_uint32_600
mph_pext_exp_uint32_700
mph_pext_exp_uint32_800
mph_pext_exp_uint32_900
mph_pext_exp_uint32_1000
mph_pext_exp_uint16_70
mph_pext_exp_uint16_80
mph_pext_exp_uint16_90
mph_pext_exp_uint16_100
mph_pext_exp_uint16_200
mph_pext_exp_uint16_300
mph_pext_exp_uint16_400
mph_pext_exp_uint16_500
mph_pext_exp_uint16_600
mph_pext_exp_uint16_700
mph_pext_exp_uint16_800
mph_pext_exp_uint16_900
mph_pext_exp_uint16_1000)

function(gen_pp_benchmarks)
set(oneValueArgs TYPE SIZE)
cmake_parse_arguments(BM "" "${oneValueArgs}" "" ${ARGN})

set(DATASET exp_${BM_TYPE}_${BM_SIZE})
set(HEADER "${CMAKE_BINARY_DIR}/benchmark/generated/${DATASET}.hpp")
set(DATA_TARGET "bm_lookup_data_${DATASET}")
gen_lookup_data(
TARGET
${DATA_TARGET}
TYPE
${BM_TYPE}
SIZE
${BM_SIZE}
OUTPUT
${HEADER})

foreach(ALG_NAME ${ALG_NAMES})
if("${ALG_NAME}_${DATASET}" IN_LIST EXCLUDED_COMBINATIONS)
continue()
endif()

set(name "${ALG_NAME}_${DATASET}_bench")
add_benchmark(
${name}
NANO
FILES
pseudo_pext.cpp
SYSTEM_LIBRARIES
cib_lookup
mph
frozen-headers)
target_compile_options(${name} PRIVATE -fconstexpr-steps=4000000000
--include=${HEADER})
target_compile_definitions(
${name} PRIVATE ALG_NAME=bench_${ALG_NAME} DATASET=${DATASET}
ANKERL_NANOBENCH_IMPLEMENT)
add_dependencies(${name} ${DATA_TARGET})
endforeach()
endfunction()

foreach(type IN ITEMS uint16 uint32)
foreach(i RANGE 1 10)
gen_pp_benchmarks(TYPE ${type} SIZE ${i})
endforeach()
foreach(i RANGE 20 100 10)
gen_pp_benchmarks(TYPE ${type} SIZE ${i})
endforeach()
foreach(i RANGE 200 1000 100)
gen_pp_benchmarks(TYPE ${type} SIZE ${i})
endforeach()
endforeach()
31 changes: 31 additions & 0 deletions benchmark/lookup/algorithms/allocator.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#pragma once

#include <cstddef>
#include <memory>

inline std::size_t allocated_size = 0;

template <typename T> class TrackingAllocator {
public:
using value_type = T;

TrackingAllocator() noexcept {}

template <typename U>
TrackingAllocator(TrackingAllocator<U> const &) noexcept {}

template <typename U> struct rebind {
using other = TrackingAllocator<U>;
};

T *allocate(std::size_t n) {
T *ptr = std::allocator<T>{}.allocate(n);
allocated_size += (n * sizeof(T));
return ptr;
}

void deallocate(T *p, std::size_t n) {
std::allocator<T>{}.deallocate(p, n);
allocated_size -= (n * sizeof(T));
}
};
48 changes: 48 additions & 0 deletions benchmark/lookup/algorithms/frozen_map.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#pragma once

#include <cstddef>
#include <cstdio>
#include <utility>

#include <frozen/map.h>
#include <nanobench.h>

template <auto data, typename T> constexpr auto make_frozen_map() {
return []<std::size_t... i>(std::index_sequence<i...>) {
return frozen::map<T, T, data.size()>{
{{static_cast<T>(data[i].first),
static_cast<T>(data[i].second)}...}};
}(std::make_index_sequence<data.size()>{});
}

template <auto data, typename T>
__attribute__((noinline, flatten)) T do_frozen_map(T k) {
constexpr static auto map = make_frozen_map<data, T>();
return map.find(k)->second;
}

template <auto data, typename T> void bench_frozen_map(auto name) {

constexpr auto map = make_frozen_map<data, T>();

printf("size: %lu\n", sizeof(map));

do_frozen_map<data, T>(T{});

T k = static_cast<T>(data[0].first);
ankerl::nanobench::Bench().minEpochIterations(2000000).run("chained", [&] {
k = map.find(k)->second;
ankerl::nanobench::doNotOptimizeAway(k);
});

auto i = std::size_t{};
ankerl::nanobench::Bench().minEpochIterations(2000000).run(
"independent", [&] {
auto v = map.find(data[i].first)->second;
i++;
if (i >= data.size()) {
i = 0;
}
ankerl::nanobench::doNotOptimizeAway(v);
});
}
48 changes: 48 additions & 0 deletions benchmark/lookup/algorithms/frozen_unordered_map.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#pragma once

#include <cstddef>
#include <cstdio>
#include <utility>

#include <frozen/unordered_map.h>
#include <nanobench.h>

template <auto data, typename T> constexpr auto make_frozen_unordered_map() {
return []<std::size_t... i>(std::index_sequence<i...>) {
return frozen::unordered_map<T, T, data.size()>{
{{static_cast<T>(data[i].first),
static_cast<T>(data[i].second)}...}};
}(std::make_index_sequence<data.size()>{});
}

template <auto data, typename T>
__attribute__((noinline, flatten)) T do_frozen_unordered_map(T k) {
constexpr static auto map = make_frozen_unordered_map<data, T>();
return map.find(k)->second;
}

template <auto data, typename T> void bench_frozen_unordered_map(auto name) {

constexpr auto map = make_frozen_unordered_map<data, T>();

printf("size: %lu\n", sizeof(map));

do_frozen_unordered_map<data, T>(T{});

T k = static_cast<T>(data[0].first);
ankerl::nanobench::Bench().minEpochIterations(2000000).run("chained", [&] {
k = map.find(k)->second;
ankerl::nanobench::doNotOptimizeAway(k);
});

auto i = std::size_t{};
ankerl::nanobench::Bench().minEpochIterations(2000000).run(
"independent", [&] {
auto v = map.find(data[i].first)->second;
i++;
if (i >= data.size()) {
i = 0;
}
ankerl::nanobench::doNotOptimizeAway(v);
});
}
52 changes: 52 additions & 0 deletions benchmark/lookup/algorithms/mph.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#pragma once

#include <array>
#include <cstddef>
#include <mph>
#include <utility>

#include <nanobench.h>

template <auto data, typename T> constexpr auto make_mph() {
constexpr static auto input_data =
[]<std::size_t... i>(std::index_sequence<i...>) {
return std::array<mph::pair<T, T>, data.size()>{
{{static_cast<T>(data[i].first),
static_cast<T>(data[i].second)}...}};
}(std::make_index_sequence<data.size()>{});

constexpr auto map = mph::hash<input_data>;

return map;
}

template <auto data, typename T>
__attribute__((noinline, flatten)) T do_mph(T k) {
constexpr static auto map = make_mph<data, T>();
return *map(k);
}

template <auto data, typename T> void bench_mph(auto name) {

constexpr auto map = make_mph<data, T>();

// printf("\nmph\n");
do_mph<data, T>(T{});

T k = static_cast<T>(data[0].first);
ankerl::nanobench::Bench().minEpochIterations(2000000).run("chained", [&] {
k = *map(k);
ankerl::nanobench::doNotOptimizeAway(k);
});

auto i = std::size_t{};
ankerl::nanobench::Bench().minEpochIterations(2000000).run(
"independent", [&] {
auto v = *map(static_cast<T>(data[i].first));
i++;
if (i >= data.size()) {
i = 0;
}
ankerl::nanobench::doNotOptimizeAway(v);
});
}
58 changes: 58 additions & 0 deletions benchmark/lookup/algorithms/mph_pext.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#pragma once

#include <array>
#include <cstddef>
#include <mph>
#include <utility>

#include <nanobench.h>

template <auto data, typename T> constexpr auto make_mph_pext() {
constexpr static auto input_data =
[]<std::size_t... i>(std::index_sequence<i...>) {
return std::array<mph::pair<T, T>, data.size()>{
{{static_cast<T>(data[i].first),
static_cast<T>(data[i].second)}...}};
}(std::make_index_sequence<data.size()>{});

constexpr auto conditional_pext_policy =
[]<auto const... ts>(auto &&...args) {
return mph::pext<32u>{}.template operator()<ts...>(
std::forward<decltype(args)>(args)...);
};

constexpr auto map = mph::hash<input_data, conditional_pext_policy>;

return map;
}

template <auto data, typename T>
__attribute__((noinline, flatten)) T do_mph_pext(T k) {
constexpr static auto map = make_mph_pext<data, T>();
return *map(k);
}

template <auto data, typename T> void bench_mph_pext(auto name) {

constexpr auto map = make_mph_pext<data, T>();

// printf("\nmph\n");
do_mph_pext<data, T>(T{});

T k = static_cast<T>(data[0].first);
ankerl::nanobench::Bench().minEpochIterations(2000000).run("chained", [&] {
k = *map(k);
ankerl::nanobench::doNotOptimizeAway(k);
});

auto i = std::size_t{};
ankerl::nanobench::Bench().minEpochIterations(2000000).run(
"independent", [&] {
auto v = *map(static_cast<T>(data[i].first));
i++;
if (i >= data.size()) {
i = 0;
}
ankerl::nanobench::doNotOptimizeAway(v);
});
}
Loading
Loading