-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding all the headers and getting the repo setup.
- Loading branch information
1 parent
069e37d
commit b421691
Showing
19 changed files
with
1,578 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--- | ||
Language: Cpp | ||
BasedOnStyle: Microsoft | ||
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
name: CMake | ||
|
||
on: | ||
push: | ||
branches: [ "main" ] | ||
pull_request: | ||
branches: [ "main" ] | ||
|
||
env: | ||
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.) | ||
BUILD_TYPE: Release | ||
|
||
jobs: | ||
build: | ||
# The CMake configure and build commands are platform agnostic and should work equally well on Windows or Mac. | ||
# You can convert this to a matrix build if you need cross-platform coverage. | ||
# See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix | ||
strategy: | ||
matrix: | ||
os: [ macos-latest, ubuntu-latest ] | ||
|
||
runs-on: ${{ matrix.os }} | ||
continue-on-error: true | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
submodules: recursive | ||
|
||
- name: Install Packages | ||
run: brew install pkg-config | ||
if: matrix.os != 'ubuntu-latest' | ||
|
||
- name: Configure CMake | ||
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make. | ||
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type | ||
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DBUILD_TESTING=ON -DBUILD_BENCHMARKING=ON | ||
|
||
- name: Build | ||
# Build your program with the given configuration | ||
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} -j$(getconf _NPROCESSORS_ONLN) --parallel 16 | ||
|
||
- name: Test | ||
working-directory: ${{github.workspace}}/build | ||
# Execute tests defined by the CMake configuration. | ||
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail | ||
run: ctest -C ${{env.BUILD_TYPE}} | ||
|
||
- name: Benchmark | ||
run: ${{github.workspace}}/build/benchmark/qname_benchmark | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
cmake_minimum_required(VERSION 3.13) | ||
|
||
# Build tests by default only if not a sub-project | ||
if(DEFINED PROJECT_NAME) | ||
option(qname_BUILD_TESTS "Build tests for qname" OFF) | ||
option(qname_BUILD_BENCHMARKS "Build benchmarks for qname" OFF) | ||
else() | ||
option(qname_BUILD_TESTS "Build tests for qname" ON) | ||
option(qname_BUILD_BENCHMARKS "Build benchmarks for qname" ON) | ||
endif() | ||
|
||
project(qname | ||
VERSION 1.0.0.0 | ||
DESCRIPTION "Quicr Name library" | ||
LANGUAGES CXX) | ||
|
||
option(CLANG_TIDY "Perform linting with clang-tidy" OFF) | ||
|
||
if(CLANG_TIDY) | ||
find_program(CLANG_TIDY_EXE NAMES "clang-tidy") | ||
if(CLANG_TIDY_EXE) | ||
set(CMAKE_CXX_CLANG_TIDY ${CLANG_TIDY_EXE}) | ||
else() | ||
message(WARNING "clang-tidy requested, but not found") | ||
endif() | ||
endif() | ||
|
||
add_subdirectory(src) | ||
|
||
include(FetchContent) | ||
|
||
if(BUILD_TESTING AND qname_BUILD_TESTS) | ||
FetchContent_Declare( | ||
doctest | ||
GIT_REPOSITORY https://github.com/doctest/doctest.git | ||
) | ||
FetchContent_MakeAvailable(doctest) | ||
|
||
include(CTest) | ||
enable_testing() | ||
add_subdirectory(test) | ||
endif() | ||
|
||
if (BUILD_BENCHMARKING AND qname_BUILD_BENCHMARKS) | ||
set(BENCHMARK_USE_BUNDLED_GTEST OFF) | ||
set(BENCHMARK_ENABLE_TESTING OFF) | ||
FetchContent_Declare( | ||
benchmark | ||
GIT_REPOSITORY https://github.com/google/benchmark.git | ||
GIT_TAG main | ||
) | ||
FetchContent_MakeAvailable(benchmark) | ||
|
||
add_subdirectory(benchmark) | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
add_executable(qname_benchmark | ||
name.cpp | ||
hex_endec.cpp) | ||
|
||
target_link_libraries(qname_benchmark PRIVATE qname benchmark::benchmark benchmark::benchmark_main) | ||
target_include_directories(qname_benchmark PRIVATE ${PROJECT_SOURCE_DIR}/src) | ||
|
||
target_compile_options(qname_benchmark | ||
PRIVATE | ||
$<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>,$<CXX_COMPILER_ID:GNU>>: -Wpedantic -Wextra -Wall> | ||
$<$<CXX_COMPILER_ID:MSVC>: >) | ||
|
||
set_target_properties(qname_benchmark | ||
PROPERTIES | ||
CXX_STANDARD 20 | ||
CXX_STANDARD_REQUIRED YES | ||
CXX_EXTENSIONS ON) | ||
if(MSVC) | ||
target_compile_definitions(qname_benchmark _CRT_SECURE_NO_WARNINGS) | ||
endif() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
#include <benchmark/benchmark.h> | ||
|
||
#include <quicr/hex_endec.h> | ||
|
||
static void | ||
HexEndec_Encode4x32_to_128(benchmark::State& state) | ||
{ | ||
quicr::HexEndec<128, 32, 32, 32, 32> format; | ||
for (auto _ : state) { | ||
format.Encode(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF); | ||
} | ||
} | ||
|
||
static void | ||
HexEndec_Decode128_to_4x32(benchmark::State& state) | ||
{ | ||
quicr::HexEndec<128, 32, 32, 32, 32> format; | ||
for (auto _ : state) { | ||
format.Decode("0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"); | ||
} | ||
} | ||
|
||
static void | ||
HexEndec_Encode4x16_to_64(benchmark::State& state) | ||
{ | ||
quicr::HexEndec<64, 16, 16, 16, 16> format; | ||
for (auto _ : state) { | ||
format.Encode(0xFFFFu, 0xFFFFu, 0xFFFFu, 0xFFFFu); | ||
} | ||
} | ||
|
||
static void | ||
HexEndec_Decode64_to_4x16(benchmark::State& state) | ||
{ | ||
quicr::HexEndec<64, 16, 16, 16, 16> format; | ||
for (auto _ : state) { | ||
format.Decode("0xFFFFFFFFFFFFFFFF"); | ||
} | ||
} | ||
|
||
BENCHMARK(HexEndec_Encode4x32_to_128); | ||
BENCHMARK(HexEndec_Decode128_to_4x32); | ||
BENCHMARK(HexEndec_Encode4x16_to_64); | ||
BENCHMARK(HexEndec_Decode64_to_4x16); | ||
|
||
static void | ||
HexEndec_RealEncode(benchmark::State& state) | ||
{ | ||
quicr::HexEndec<128, 24, 8, 24, 8, 16, 48> format; | ||
auto time = std::time(0); | ||
const uint32_t orgId = 0x00A11CEE; | ||
const uint8_t appId = 0x00; | ||
const uint32_t confId = 0x00F00001; | ||
const uint8_t mediaType = 0x00 | 0x1; | ||
const uint16_t clientId = 0xFFFF; | ||
const uint64_t uniqueId = time; | ||
for (auto _ : state) { | ||
format.Encode(orgId, appId, confId, mediaType, clientId, uniqueId); | ||
} | ||
} | ||
|
||
static void | ||
HexEndec_RealDecode(benchmark::State& state) | ||
{ | ||
quicr::HexEndec<128, 24, 8, 24, 8, 16, 48> format; | ||
quicr::Name qname = 0xA11CEE00F00001000000000000000000_name; | ||
for (auto _ : state) { | ||
format.Decode(qname); | ||
} | ||
} | ||
|
||
BENCHMARK(HexEndec_RealEncode); | ||
BENCHMARK(HexEndec_RealDecode); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
#include <benchmark/benchmark.h> | ||
|
||
#include <quicr_name> | ||
#include <vector> | ||
|
||
static void | ||
Name_ConstructFromHexString(benchmark::State& state) | ||
{ | ||
std::string str = "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"; | ||
for (auto _ : state) { | ||
[[maybe_unused]] quicr::Name __(str); | ||
} | ||
} | ||
|
||
static void | ||
Name_ConstructFromHexStringView(benchmark::State& state) | ||
{ | ||
std::string_view str = "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"; | ||
for (auto _ : state) { | ||
[[maybe_unused]] quicr::Name __(str); | ||
} | ||
} | ||
|
||
static void | ||
Name_ConstructFromVector(benchmark::State& state) | ||
{ | ||
std::vector<uint8_t> data = { | ||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, | ||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF | ||
}; | ||
for (auto _ : state) { | ||
[[maybe_unused]] quicr::Name __(data); | ||
} | ||
} | ||
|
||
static void | ||
Name_ConstructFromBytePointer(benchmark::State& state) | ||
{ | ||
std::vector<uint8_t> vec_data = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, | ||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, | ||
0xFF, 0xFF, 0xFF, 0xFF }; | ||
|
||
uint8_t* data = vec_data.data(); | ||
size_t length = vec_data.size(); | ||
|
||
for (auto _ : state) { | ||
[[maybe_unused]] quicr::Name __(data, length); | ||
} | ||
} | ||
|
||
static void | ||
Name_CopyConstruct(benchmark::State& state) | ||
{ | ||
quicr::Name name = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF_name; | ||
for (auto _ : state) { | ||
[[maybe_unused]] quicr::Name __(name); | ||
} | ||
} | ||
|
||
static void | ||
Name_LeftShift(benchmark::State& state) | ||
{ | ||
quicr::Name name = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF_name; | ||
for (auto _ : state) { | ||
name << 64; | ||
} | ||
} | ||
|
||
static void | ||
Name_RightShift(benchmark::State& state) | ||
{ | ||
quicr::Name name = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF_name; | ||
for (auto _ : state) { | ||
name >> 64; | ||
} | ||
} | ||
|
||
static void | ||
Name_Add(benchmark::State& state) | ||
{ | ||
quicr::Name name = 0x0_name; | ||
for (auto _ : state) { | ||
++name; | ||
} | ||
} | ||
|
||
static void | ||
Name_Sub(benchmark::State& state) | ||
{ | ||
quicr::Name name = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF_name; | ||
for (auto _ : state) { | ||
--name; | ||
} | ||
} | ||
|
||
static void | ||
Name_ToHex(benchmark::State& state) | ||
{ | ||
quicr::Name name = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF_name; | ||
for (auto _ : state) { | ||
name.to_hex(); | ||
} | ||
} | ||
|
||
BENCHMARK(Name_ConstructFromHexString); | ||
BENCHMARK(Name_ConstructFromHexStringView); | ||
BENCHMARK(Name_ConstructFromVector); | ||
BENCHMARK(Name_ConstructFromBytePointer); | ||
BENCHMARK(Name_CopyConstruct); | ||
BENCHMARK(Name_LeftShift); | ||
BENCHMARK(Name_RightShift); | ||
BENCHMARK(Name_Add); | ||
BENCHMARK(Name_Sub); | ||
BENCHMARK(Name_ToHex); | ||
|
||
constexpr quicr::Name object_id_mask = 0x00000000000000000000000000001111_name; | ||
constexpr quicr::Name group_id_mask = 0x00000000000000000000111111110000_name; | ||
static void | ||
Name_RealArithmetic(benchmark::State& state) | ||
{ | ||
quicr::Name name = 0xA11CEE00F00001000000000000000000_name; | ||
for (auto _ : state) { | ||
name = (name & ~object_id_mask) | (++name & object_id_mask); | ||
|
||
auto group_id_bits = (++(name >> 16) << 16) & group_id_mask; | ||
name = ((name & ~group_id_mask) | group_id_bits) & ~object_id_mask; | ||
} | ||
} | ||
|
||
BENCHMARK(Name_RealArithmetic); |
Oops, something went wrong.