Skip to content

Commit

Permalink
Adding build system
Browse files Browse the repository at this point in the history
  • Loading branch information
Konstantin Vladimirov committed Mar 1, 2024
1 parent ed9a716 commit 2ecf18f
Show file tree
Hide file tree
Showing 13 changed files with 198 additions and 0 deletions.
18 changes: 18 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
cmake_minimum_required(VERSION 3.11)
project("benchmarks")

enable_testing()
file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/CSVS)

find_package(cppbenchmark REQUIRED)

add_custom_target(runall)

add_subdirectory(coro-fibs)
add_subdirectory(excret)
add_subdirectory(inline)
add_subdirectory(noexcept-qsort)
add_subdirectory(ranges-filter)
add_subdirectory(ranges-projector)
add_subdirectory(virtual-inline)
add_subdirectory(virtual-overhead)
7 changes: 7 additions & 0 deletions conanfile.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[requires]
cppbenchmark/cci.20201029
[generators]
CMakeDeps
CMakeToolchain
[layout]
cmake_layout
11 changes: 11 additions & 0 deletions coro-fibs/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
SET(TNAME coro-fibs)

add_executable(${TNAME} corofibs.cc sumfib_module.cc)
target_compile_features(${TNAME} PRIVATE cxx_std_20)
target_link_libraries(${TNAME} cppbenchmark::cppbenchmark)

add_test(
NAME TEST_${TNAME}
COMMAND ${TNAME} -q -o csv > ${CMAKE_BINARY_DIR}/CSVS/${TNAME}.csv)
set_tests_properties(${TEST_TARGET} PROPERTIES DEPENDS ${TNAME})

11 changes: 11 additions & 0 deletions excret/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
SET(TNAME exc_ret)

add_executable(${TNAME} exc_ret_1.cc exc_ret_2.cc)
target_compile_features(${TNAME} PRIVATE cxx_std_20)
target_link_libraries(${TNAME} cppbenchmark::cppbenchmark)

add_test(
NAME TEST_${TNAME}
COMMAND ${TNAME} -q -o csv > ${CMAKE_BINARY_DIR}/CSVS/${TNAME}.csv)
set_tests_properties(${TEST_TARGET} PROPERTIES DEPENDS ${TNAME})

11 changes: 11 additions & 0 deletions inline/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
SET(TNAME extswap)

add_executable(${TNAME} extswap.cc partition.cc)
target_compile_features(${TNAME} PRIVATE cxx_std_20)
target_link_libraries(${TNAME} cppbenchmark::cppbenchmark)

add_test(
NAME TEST_${TNAME}
COMMAND ${TNAME} -q -o csv > ${CMAKE_BINARY_DIR}/CSVS/${TNAME}.csv)
set_tests_properties(${TEST_TARGET} PROPERTIES DEPENDS ${TNAME})

22 changes: 22 additions & 0 deletions noexcept-qsort/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
SET(TNAME exc_qsort)

add_executable(${TNAME} exc_qsort.cc)
target_compile_features(${TNAME} PRIVATE cxx_std_20)
target_link_libraries(${TNAME} cppbenchmark::cppbenchmark)

add_test(
NAME TEST_${TNAME}
COMMAND ${TNAME} -q -o csv > ${CMAKE_BINARY_DIR}/CSVS/${TNAME}.csv)
set_tests_properties(${TEST_TARGET} PROPERTIES DEPENDS ${TNAME})

SET(TNAME exc_partition)

add_executable(${TNAME} exc_partition.cc)
target_compile_features(${TNAME} PRIVATE cxx_std_20)
target_link_libraries(${TNAME} cppbenchmark::cppbenchmark)

add_test(
NAME TEST_${TNAME}
COMMAND ${TNAME} -q -o csv > ${CMAKE_BINARY_DIR}/CSVS/${TNAME}.csv)
set_tests_properties(${TEST_TARGET} PROPERTIES DEPENDS ${TNAME})

11 changes: 11 additions & 0 deletions ranges-filter/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
SET(TNAME filter)

add_executable(${TNAME} filter.cc)
target_compile_features(${TNAME} PRIVATE cxx_std_20)
target_link_libraries(${TNAME} cppbenchmark::cppbenchmark)

add_test(
NAME TEST_${TNAME}
COMMAND ${TNAME} -q -o csv > ${CMAKE_BINARY_DIR}/CSVS/${TNAME}.csv)
set_tests_properties(${TEST_TARGET} PROPERTIES DEPENDS ${TNAME})

11 changes: 11 additions & 0 deletions ranges-projector/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
SET(TNAME projector)

add_executable(${TNAME} projector.cc)
target_compile_features(${TNAME} PRIVATE cxx_std_20)
target_link_libraries(${TNAME} cppbenchmark::cppbenchmark)

add_test(
NAME TEST_${TNAME}
COMMAND ${TNAME} -q -o csv > ${CMAKE_BINARY_DIR}/CSVS/${TNAME}.csv)
set_tests_properties(${TEST_TARGET} PROPERTIES DEPENDS ${TNAME})

42 changes: 42 additions & 0 deletions ranges-projector/projector.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#include <algorithm>
#include <random>
#include <ranges>
#include <vector>

#include "benchmark/cppbenchmark.h"

namespace ranges = std::ranges;
namespace views = std::views;

struct S { int x, y; };

constexpr int N = 100;
constexpr int NBMK = 1000;

class TestFixture {
protected:
std::vector<S> v;
std::vector<int> w;
std::random_device r;
std::mt19937 g;

TestFixture() : g(r()) {
v.resize(N);
w.resize(N);
std::uniform_int_distribution<int> dist {0, 100};
auto gen = [&, this]() -> S { return {dist(g), dist(g)}; };
std::generate(std::begin(v), std::end(v), gen);
}
};

BENCHMARK_FIXTURE(TestFixture, "TransformComparator") {
for (int i = 0; i < NBMK; ++i)
ranges::transform(v.begin(), v.end(), w.begin(), [](const auto& a) { return a.x * 2; });
}

BENCHMARK_FIXTURE(TestFixture, "TransformProjector") {
for (int i = 0; i < NBMK; ++i)
ranges::transform(v.begin(), v.end(), w.begin(), [](auto x) { return x * 2; }, &S::x);
}

BENCHMARK_MAIN()
10 changes: 10 additions & 0 deletions runme.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,13 @@ export LIBS="-lcppbenchmark -lHdrHistogram -lcpp-optparse"

clang++ -O2 ./inline/partition.cc ./inline/extswap.cc ${OPTIONS} ${LIBS}
./a.out -q -o csv | tee partition.csv
clang++ -O2 ./virtual-overhead/virtual-1.cc ./virtual-overhead/virtual-2.cc ${OPTIONS} ${LIBS}
./a.out -q -o csv | tee virtual.csv
clang++ -O2 ./virtual-overhead/virtual-shuffle-1.cc ./virtual-overhead/virtual-shuffle-2.cc ${OPTIONS} ${LIBS}
./a.out -q -o csv | tee virtual-shuffle.csv




clang++ -O2 -std=c++20 ./ranges-projector/projector.cc ${OPTIONS} ${LIBS}
./a.out -q -o csv | tee ranges-proj.csv
11 changes: 11 additions & 0 deletions virtual-inherit/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
SET(TNAME virtinh)

add_executable(${TNAME} virtinh.cc fmodule.cc)
target_compile_features(${TNAME} PRIVATE cxx_std_20)
target_link_libraries(${TNAME} cppbenchmark::cppbenchmark)

add_test(
NAME TEST_${TNAME}
COMMAND ${TNAME} -q -o csv > ${CMAKE_BINARY_DIR}/CSVS/${TNAME}.csv)
set_tests_properties(${TEST_TARGET} PROPERTIES DEPENDS ${TNAME})

11 changes: 11 additions & 0 deletions virtual-inline/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
SET(TNAME virtinl)

add_executable(${TNAME} virtinl.cc fmodule.cc)
target_compile_features(${TNAME} PRIVATE cxx_std_20)
target_link_libraries(${TNAME} cppbenchmark::cppbenchmark)

add_test(
NAME TEST_${TNAME}
COMMAND ${TNAME} -q -o csv > ${CMAKE_BINARY_DIR}/CSVS/${TNAME}.csv)
set_tests_properties(${TEST_TARGET} PROPERTIES DEPENDS ${TNAME})

22 changes: 22 additions & 0 deletions virtual-overhead/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
SET(TNAME virtual)

add_executable(${TNAME} virtual-1.cc virtual-2.cc)
target_compile_features(${TNAME} PRIVATE cxx_std_20)
target_link_libraries(${TNAME} cppbenchmark::cppbenchmark)

add_test(
NAME TEST_${TNAME}
COMMAND ${TNAME} -q -o csv > ${CMAKE_BINARY_DIR}/CSVS/${TNAME}.csv)
set_tests_properties(${TEST_TARGET} PROPERTIES DEPENDS ${TNAME})

SET(TNAME virtual-shuffle)

add_executable(${TNAME} virtual-shuffle-1.cc virtual-shuffle-2.cc)
target_compile_features(${TNAME} PRIVATE cxx_std_20)
target_link_libraries(${TNAME} cppbenchmark::cppbenchmark)

add_test(
NAME TEST_${TNAME}
COMMAND ${TNAME} -q -o csv > ${CMAKE_BINARY_DIR}/CSVS/${TNAME}.csv)
set_tests_properties(${TEST_TARGET} PROPERTIES DEPENDS ${TNAME})

0 comments on commit 2ecf18f

Please sign in to comment.