Skip to content
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
1 change: 1 addition & 0 deletions benchmark/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
add_executable(dd_trace_cpp-benchmark
benchmark.cpp
hasher.cpp
trace_id_bench.cpp
)

# Google Benchmark is included as a git submodule.
Expand Down
54 changes: 54 additions & 0 deletions benchmark/trace_id_bench.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#include <benchmark/benchmark.h>
#include <datadog/trace_id.h>

#include "datadog/hex.h"

namespace {
namespace dd = datadog::tracing;

void BM_TraceID_HexPadded(benchmark::State& state) {
const dd::TraceID id{0xDEADBEEFCAFEBABEULL, 0x0102030405060708ULL};
for (auto _ : state) {
auto result = id.hex_padded();
benchmark::DoNotOptimize(result);
}
}
BENCHMARK(BM_TraceID_HexPadded);

void BM_TraceID_ParseHex_128bit(benchmark::State& state) {
const std::string input{"0102030405060708deadbeefcafebabe"};
for (auto _ : state) {
auto result = dd::TraceID::parse_hex(input);
benchmark::DoNotOptimize(result);
}
}
BENCHMARK(BM_TraceID_ParseHex_128bit);

void BM_TraceID_ParseHex_64bit(benchmark::State& state) {
const std::string input{"deadbeefcafebabe"};
for (auto _ : state) {
auto result = dd::TraceID::parse_hex(input);
benchmark::DoNotOptimize(result);
}
}
BENCHMARK(BM_TraceID_ParseHex_64bit);

void BM_HexPadded_uint64(benchmark::State& state) {
const std::uint64_t value = 0xDEADBEEFCAFEBABEULL;
for (auto _ : state) {
auto result = dd::hex_padded(value);
benchmark::DoNotOptimize(result);
}
}
BENCHMARK(BM_HexPadded_uint64);

void BM_Hex_uint64(benchmark::State& state) {
const std::uint64_t value = 0xDEADBEEFCAFEBABEULL;
for (auto _ : state) {
auto result = dd::hex(value);
benchmark::DoNotOptimize(result);
}
}
BENCHMARK(BM_Hex_uint64);

} // namespace