Skip to content
Closed
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
47 changes: 47 additions & 0 deletions benchmark/trace_id_bench.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#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, dd::TraceID id) {
for (auto _ : state) {
auto result = id.hex_padded();
benchmark::DoNotOptimize(result);
}
}
BENCHMARK_CAPTURE(BM_TraceID_HexPadded, NoPadding,
dd::TraceID{0xDEADBEEFCAFEBABEULL, 0x0102030405060708ULL});
BENCHMARK_CAPTURE(BM_TraceID_HexPadded, WithPadding, dd::TraceID{1, 0});

void BM_TraceID_ParseHex(benchmark::State& state, std::string input) {
for (auto _ : state) {
auto result = dd::TraceID::parse_hex(input);
benchmark::DoNotOptimize(result);
}
}
BENCHMARK_CAPTURE(BM_TraceID_ParseHex, 64bit, std::string{"deadbeefcafebabe"});
BENCHMARK_CAPTURE(BM_TraceID_ParseHex, 128bit,
std::string{"0102030405060708deadbeefcafebabe"});

void BM_HexPadded_uint64(benchmark::State& state, std::uint64_t value) {
for (auto _ : state) {
auto result = dd::hex_padded(value);
benchmark::DoNotOptimize(result);
}
}
BENCHMARK_CAPTURE(BM_HexPadded_uint64, NoPadding, 0xDEADBEEFCAFEBABEULL);
BENCHMARK_CAPTURE(BM_HexPadded_uint64, WorstCasePadding, 0x1ULL);

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
Loading