Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mbkkt/add arangodb #14

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ BraceWrapping:
BeforeLambdaBody: true
AlignEscapedNewlines: Right
ContinuationIndentWidth: 2
ConstructorInitializerIndentWidth: 2
AlignAfterOpenBracket: Align # TODO(MBkkt) Try BlockIndent clang-format 15

IncludeCategories:
Expand All @@ -32,3 +33,4 @@ IncludeCategories:
- Regex: '.*' # other libraries (system headers in our case)
Priority: 50
IncludeBlocks: Regroup
IndentPPDirectives: AfterHash
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -1 +1 @@
* @MBkkt
* @MBkkt
15 changes: 8 additions & 7 deletions .github/workflows/format.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
name: Format

on:
workflow_dispatch:
push:
branches: [ master, main ]
paths-ignore: [ '**/result/**', '**.md' ]
branches: [ main ]
paths: [ '**.cpp', '**.hpp' ]
pull_request:
branches: [ master, main ]
paths-ignore: [ '**/result/**', '**.md' ]
branches: [ main ]
paths: [ '**.cpp', '**.hpp' ]

jobs:
# TODO(MBkkt) clang-format 14, now this extension doesn't work, because clang-14 not really released yet
Expand All @@ -16,17 +17,17 @@ jobs:
# TODO(MBkkt) Add option or workflow for reformat

main:
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
strategy:
fail-fast: false
matrix:
path:
- '.'

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Run clang-format style check
uses: jidicula/clang-format-action@v4.5.0
uses: jidicula/clang-format-action@v4.6.2
with:
clang-format-version: 13
check-path: ${{ matrix.path }}
49 changes: 32 additions & 17 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
@@ -1,54 +1,69 @@
name: Sanitizer
name: Linux

on:
workflow_dispatch:
push:
branches: [ master, main ]
paths-ignore: [ '**/result/**', '**.md' ]
branches: [ main ]
paths: [ '**.cpp', '**.hpp', '**.cmake', '**/CMakeLists.txt' ]
pull_request:
branches: [ master, main ]
paths-ignore: [ '**/result/**', '**.md' ]
branches: [ main ]
paths: [ '**.cpp', '**.hpp', '**.cmake' ]

jobs:
main:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ ubuntu-20.04 ]
os: [ ubuntu-22.04 ]
build_type: [ Debug, RelWithDebInfo ]
compiler: [ clang_libcxx, clang_libstdcxx, gcc_libstdcxx ]

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- name: Update deps on Linux
run: |
sudo apt-get update
sudo wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
sudo add-apt-repository "deb http://apt.llvm.org/focal/ llvm-toolchain-focal-14 main"
sudo add-apt-repository "deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-14 main"
sudo apt-get update
sudo apt-get install ninja-build gcc-11 g++-11 libstdc++-11-dev clang-14 lld-14 libc++-14-dev libc++abi-14-dev libboost-thread-dev
sudo ln -sf /usr/bin/lld-14 /usr/local/bin/ld
sudo update-alternatives \
--install /usr/bin/gcc gcc /usr/bin/gcc-11 200 \
--slave /usr/bin/g++ g++ /usr/bin/g++-11 \
--slave /usr/bin/gcc-ar gcc-ar /usr/bin/gcc-ar-11 \
--slave /usr/bin/gcc-nm gcc-nm /usr/bin/gcc-nm-11 \
--slave /usr/bin/gcc-ranlib gcc-ranlib /usr/bin/gcc-ranlib-11 \
--slave /usr/bin/gcov gcov /usr/bin/gcov-11 \
--slave /usr/bin/gcov-tool gcov-tool /usr/bin/gcov-tool-11 \
--slave /usr/bin/gcov-dump gcov-dump /usr/bin/gcov-dump-11
sudo update-alternatives --auto gcc
sudo update-alternatives \
--install /usr/bin/cpp cpp /usr/bin/cpp-11 200
sudo update-alternatives --auto cpp

- name: Configure CMake Posix
run: |
build_type=${{ matrix.build_type }}
dir="build_${{ matrix.compiler }}"
if [[ "${{ matrix.compiler }}" == "gcc_libstdcxx" ]]; then
c_compiler=gcc-11; cxx_compiler=g++-11
cxx_compiler=g++-11
else
c_compiler=clang-14; cxx_compiler=clang++-14
cxx_compiler=clang++-14
fi
if [[ "${{ matrix.compiler }}" == "clang_libcxx" ]]; then
options="-DLIBCXX=ON -DSTD=ON -DYACLIB=main"
options="-DLIBCXX=ON"
else
options=" -DSTD=ON -DYACLIB=main -DBOOST_THREAD=ON"
options="-DBOOST_THREAD=ON"
fi
cmake -S . -B $dir \
-DCMAKE_BUILD_TYPE=$build_type \
-DCMAKE_C_COMPILER=${c_compiler} \
-DCMAKE_CXX_COMPILER=${cxx_compiler} \
-G"Ninja" \
cmake -S . -B $dir \
-DCMAKE_BUILD_TYPE=$build_type \
-DCMAKE_CXX_COMPILER=${cxx_compiler} \
-G"Ninja" \
-DSTD=ON \
-DYACLIB=v2022.08.23 \
$options

- name: Build
Expand Down
120 changes: 110 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,21 @@ if (BENCH_SOURCE_DIR STREQUAL BENCH_BINARY_DIR)
endif ()

# Set variables
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_VISIBILITY_PRESET hidden)

set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_C_EXTENSIONS OFF)
set(CMAKE_C_VISIBILITY_PRESET hidden)

set(CMAKE_VISIBILITY_INLINES_HIDDEN ON)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

message("COMPILE_OPTIONS: ${COMPILE_OPTIONS}")
message("LINK_OPTIONS : ${LINK_OPTIONS}")

include(FetchContent)

if (LIBCXX)
add_compile_options(-stdlib=libc++)
add_compile_options(-stdlib=libc++ -fno-inline)
add_link_options(-stdlib=libc++ -lc++abi)
endif ()

Expand All @@ -40,7 +37,6 @@ set(UTIL_HEADERS
find_package(benchmark QUIET)

if (NOT BENCHMARK_FOUND)
include(FetchContent)
if (NOT BENCHMARK_FOUND)
set(BENCHMARK_ENABLE_TESTING NO)
FetchContent_Declare(
Expand All @@ -52,4 +48,108 @@ if (NOT BENCHMARK_FOUND)
endif ()
endif ()

add_subdirectory(future)
function(add_bench BENCH_NAME)
add_executable(${BENCH_NAME} ${CMAKE_CURRENT_SOURCE_DIR}/test/${BENCH_NAME}/${BENCH_NAME}.cpp)
target_link_libraries(${BENCH_NAME}
PRIVATE ${GTEST_BOTH_LIBRARIES}
PRIVATE benchmark::benchmark
PRIVATE ${PROJECT_NAME}
)

if (STD)
target_compile_definitions(${BENCH_NAME} PUBLIC STD_ENABLE)
endif ()
if (YACLIB)
target_compile_definitions(${BENCH_NAME} PUBLIC YACLIB_ENABLE)
endif ()
if (CPPCORO)
target_compile_definitions(${BENCH_NAME} PUBLIC CPPCORO_ENABLE)
endif ()
if (FOLLY)
target_compile_definitions(${BENCH_NAME} PUBLIC FOLLY_ENABLE)
endif ()
if (ARANGODB)
target_compile_definitions(${BENCH_NAME} PUBLIC ARANGODB_ENABLE)
endif ()
if (BOOST_THREAD)
target_compile_definitions(${BENCH_NAME} PUBLIC BOOST_THREAD_ENABLE)
endif ()
if (QT)
target_compile_definitions(${BENCH_NAME} PUBLIC QT_ENABLE)
endif ()
if (EXPERIMENTAL)
target_compile_definitions(${BENCH_NAME} PUBLIC EXPERIMENTAL_ENABLE)
endif ()

add_test(NAME ${BENCH_NAME} COMMAND ${BENCH_NAME})
endfunction()

find_package(Threads REQUIRED)
link_libraries(Threads::Threads)
include_directories(vendor)

if (YACLIB) # v2022.08.31
FetchContent_Declare(yaclib
GIT_REPOSITORY https://github.com/YACLib/YACLib.git
GIT_TAG "${YACLIB}"
)
list(APPEND YACLIB_FLAGS "CORO")
FetchContent_MakeAvailable(yaclib)
link_libraries(yaclib)
endif ()
if (FOLLY)
find_package(glog CONFIG REQUIRED) # Ad-hoc
find_package(folly CONFIG REQUIRED)
include_directories(${FOLLY_INCLUDE_DIR})
link_libraries(Folly::folly)
endif ()
if (ARANGODB)
add_library(arangodb STATIC
${CMAKE_CURRENT_SOURCE_DIR}/vendor/arangodb/futures/Future.cpp
)
endif ()
if (BOOST_THREAD)
find_package(Boost COMPONENTS thread REQUIRED)
link_libraries(Boost::thread)
endif ()
if (QT)
find_package(Qt6 COMPONENTS Concurrent REQUIRED)
link_libraries(Qt6::Concurrent)
endif ()
if (EXPERIMENTAL)
add_link_options(-lc++experimental)
endif ()
if (CPPCORO)
FetchContent_Declare(cppcoro
GIT_REPOSITORY https://github.com/YACLib/cppcoro-for-benchmark.git
GIT_TAG main
)
FetchContent_MakeAvailable(cppcoro)
link_libraries(cppcoro)
endif ()

macro(add_files)
set(BENCH_HEADERS ${BENCH_HEADERS} PARENT_SCOPE)
set(BENCH_SOURCES ${BENCH_SOURCES} PARENT_SCOPE)
endmacro()

add_subdirectory(bind)
add_subdirectory(bench)
add_library(${PROJECT_NAME} STATIC)

target_sources(${PROJECT_NAME}
PRIVATE ${BENCH_SOURCES}
PRIVATE ${BENCH_HEADERS}
)

target_include_directories(${PROJECT_NAME}
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}
)

target_link_libraries(${PROJECT_NAME}
PRIVATE ${GTEST_BOTH_LIBRARIES}
PUBLIC benchmark::benchmark
)

add_bench(future)
add_bench(coro)
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Results

Future benchmark [results](future/result/RESULTS.md).
Future benchmark [results](test/future/result/RESULTS.md).

## How to add your own results

Expand Down
1 change: 1 addition & 0 deletions bench/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add_files()
19 changes: 19 additions & 0 deletions bench/async_mutex.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#pragma once

#include <thread>

#include <benchmark/benchmark.h>

namespace bench {

template <typename Library>
void AsyncMutex(benchmark::State& state) {
auto* executor = Library::AcquireExecutor(std::thread::hardware_concurrency());
for (auto _ : state) {
Library::AsyncMutex(executor);
executor->Restart();
}
Library::ReleaseExecutor(executor);
}

} // namespace bench
23 changes: 23 additions & 0 deletions bench/collatz.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#pragma once

#include <benchmark/benchmark.h>

namespace bench {

template <typename Library>
void CollatzEager(benchmark::State& state) {
const auto x = state.range(0);
for (auto _ : state) {
Library::CollatzEager(x);
}
}

template <typename Library>
void CollatzLazy(benchmark::State& state) {
const auto x = state.range(0);
for (auto _ : state) {
Library::CollatzLazy(x);
}
}

} // namespace bench
11 changes: 5 additions & 6 deletions future/bench/complex.hpp → bench/complex.hpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
#pragma once

#include <util/blob.hpp>

#include <cstddef>

#include <benchmark/benchmark.h>

namespace bench {

template <std::size_t Size>
struct Blob {
std::byte buffer[Size];
};

template <typename Library, size_t N>
template <typename Library, std::size_t N>
void ComplexBlob(benchmark::State& state) {
for (auto _ : state) {
if constexpr (N == 0) {
Expand Down
2 changes: 2 additions & 0 deletions future/bench/contention.hpp → bench/contention.hpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#pragma once

#include <benchmark/benchmark.h>

namespace bench {
Expand Down
9 changes: 9 additions & 0 deletions future/bench/creation.hpp → bench/creation.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
#pragma once

#include <benchmark/benchmark.h>

namespace bench {

template <typename Library>
void ConstantTask(benchmark::State& state) {
for (auto _ : state) {
Library::CreateTask();
}
}

template <typename Library>
void ConstantFuture(benchmark::State& state) {
for (auto _ : state) {
Expand Down
Loading