-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathtrace_id_bench.cpp
More file actions
54 lines (46 loc) · 1.4 KB
/
trace_id_bench.cpp
File metadata and controls
54 lines (46 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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