blob: 5aa5f7dc2d9117fa25a13e40ee7408b1d22b8447 (
plain) (
blame)
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
55
|
#include <benchmark/benchmark.h>
#include <library/cpp/yt/system/thread_id.h>
#include <library/cpp/yt/system/thread_name.h>
#include <util/system/thread.h>
namespace NYT {
namespace {
////////////////////////////////////////////////////////////////////////////////
void BM_GetSystemThreadId(benchmark::State& state)
{
// Cached gettid: only the first call per thread hits the kernel.
for (auto _ : state) {
benchmark::DoNotOptimize(GetSystemThreadId());
}
}
BENCHMARK(BM_GetSystemThreadId);
void BM_GetSequentialThreadId(benchmark::State& state)
{
for (auto _ : state) {
benchmark::DoNotOptimize(GetSequentialThreadId());
}
}
BENCHMARK(BM_GetSequentialThreadId);
void BM_RawGetTid(benchmark::State& state)
{
// Uncached gettid syscall, for comparison.
for (auto _ : state) {
benchmark::DoNotOptimize(::TThread::CurrentThreadNumericId());
}
}
BENCHMARK(BM_RawGetTid);
void BM_GetCurrentThreadName(benchmark::State& state)
{
// TLS-cached thread name (also read by TOriginAttributes::Capture).
for (auto _ : state) {
benchmark::DoNotOptimize(GetCurrentThreadName());
}
}
BENCHMARK(BM_GetCurrentThreadName);
////////////////////////////////////////////////////////////////////////////////
} // namespace
} // namespace NYT
|