Skip to content

Commit

Permalink
Added conversions. (#4)
Browse files Browse the repository at this point in the history
* Big cleanup, optimisation, added conversions.

* Add missing include.

* Fixing build.

* Cleanup and reduction. Add namespace docs.

* Fix constexpr.

* Fix build.
  • Loading branch information
GhostofCookie committed Jun 27, 2023
1 parent 812cb09 commit a8bc25a
Show file tree
Hide file tree
Showing 12 changed files with 919 additions and 657 deletions.
11 changes: 10 additions & 1 deletion .clang-format
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
---
Language: Cpp
BasedOnStyle: Microsoft
BasedOnStyle: Mozilla

AllowShortIfStatementsOnASingleLine: true
AllowShortFunctionsOnASingleLine: true
AllowShortBlocksOnASingleLine: true
AlwaysBreakTemplateDeclarations: Yes
AlwaysBreakAfterReturnType: None
AlwaysBreakAfterDefinitionReturnType: None
BreakAfterAttributes: Leave
BreakBeforeBraces: Allman
ColumnLimit: 120
IndentWidth: 4
PackConstructorInitializers: NextLine
...

42 changes: 41 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,41 @@
# qname
# qname

[![CMake](https://github.com/Quicr/qname/actions/workflows/cmake.yml/badge.svg?branch=main)](https://github.com/Quicr/qname/actions/workflows/cmake.yml)

A library for the QUICR Name and Namespace type definitions.

## Including in your Project

### CMake

To include qname in your project, simply add `qname` or `quicr::name` to your `target_link_libraries`:
```cmake
target_link_libraries(project_name PUBLIC/PRIVATE/INTERFACE qname)
# Or
target_link_libraries(project_name PUBLIC/PRIVATE/INTERFACE quicr::name)
```

## Building

To build qname on it's own, simply use
```bash
cmake -B build
cmake --build build
```

To build with tests, simply add the `BUILD_TESTING` flag during configuration:
```bash
cmake -B build -DBUILD_TESTING=ON
```

To build with benchmarking, simply add the `BUILD_BENCHMARKING` flag during configuration:
```bash
cmake -B build -DBUILD_BENCHMARKING=ON
```

Example of a full build configuration, including testing and benchmarking:
```bash
cmake -B build -DBUILD_TESTING=ON -DBUILD_BENCHMARKING=ON
cmake --build build
```
1 change: 1 addition & 0 deletions benchmark/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
add_executable(qname_benchmark
name.cpp
namespace.cpp
hex_endec.cpp)

target_link_libraries(qname_benchmark PRIVATE qname benchmark::benchmark benchmark::benchmark_main)
Expand Down
108 changes: 58 additions & 50 deletions benchmark/hex_endec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,72 +2,80 @@

#include <quicr/hex_endec.h>

static void
HexEndec_Encode4x32_to_128(benchmark::State& state)
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);
}
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)
static void HexEndec_Decode128_to_4x32(benchmark::State& state)
{
quicr::HexEndec<128, 32, 32, 32, 32> format;
for (auto _ : state) {
format.Decode("0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF");
}
quicr::HexEndec<128, 32, 32, 32, 32> format;
for (auto _ : state)
{
format.Decode("0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF");
}
}

static void
HexEndec_Encode4x16_to_64(benchmark::State& state)
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);
}
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)
static void HexEndec_Decode64_to_4x16(benchmark::State& state)
{
quicr::HexEndec<64, 16, 16, 16, 16> format;
for (auto _ : state) {
format.Decode("0xFFFFFFFFFFFFFFFF");
}
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)
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);
}
quicr::HexEndec<128, 24, 8, 24, 8, 16, 48> format;
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 = 0u;
for (auto _ : state)
{
format.Encode(orgId, appId, confId, mediaType, clientId, uniqueId);
}
}

static void
HexEndec_RealDecode(benchmark::State& state)
static void HexEndec_RealDecode_Name(benchmark::State& state)
{
quicr::HexEndec<128, 24, 8, 24, 8, 16, 48> format;
quicr::Name qname = 0xA11CEE00F00001000000000000000000_name;
for (auto _ : state) {
format.Decode(qname);
}
quicr::HexEndec<128, 24, 8, 24, 8, 16, 48> format;
quicr::Name qname = 0xA11CEE00F00001000000000000000000_name;
for (auto _ : state)
{
[[maybe_unused]] auto __ = format.Decode(qname);
}
}
static void HexEndec_RealDecode_String(benchmark::State& state)
{
quicr::HexEndec<128, 24, 8, 24, 8, 16, 48> format;
quicr::Name qname = 0xA11CEE00F00001000000000000000000_name;
for (auto _ : state)
{
[[maybe_unused]] auto __ = format.Decode(qname);
}
}

BENCHMARK(HexEndec_Encode4x32_to_128);
BENCHMARK(HexEndec_Decode128_to_4x32);
BENCHMARK(HexEndec_Encode4x16_to_64);
BENCHMARK(HexEndec_Decode64_to_4x16);
BENCHMARK(HexEndec_RealEncode);
BENCHMARK(HexEndec_RealDecode);
BENCHMARK(HexEndec_RealDecode_Name);
BENCHMARK(HexEndec_RealDecode_String);
Loading

0 comments on commit a8bc25a

Please sign in to comment.