summaryrefslogtreecommitdiffstats
path: root/library/cpp/yt/system/benchmarks/process.cpp
blob: 74b4b6b1e13ce1a9b797220785a8f698ae839e24 (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
#include <benchmark/benchmark.h>

#include <library/cpp/yt/system/process_id.h>

#include <util/system/getpid.h>

namespace NYT {
namespace {

////////////////////////////////////////////////////////////////////////////////

void BM_GetProcessId(benchmark::State& state)
{
    // Cached getpid: only the first call hits the kernel.
    for (auto _ : state) {
        benchmark::DoNotOptimize(GetProcessId());
    }
}

BENCHMARK(BM_GetProcessId);

void BM_RawGetPid(benchmark::State& state)
{
    // Uncached getpid syscall (uncached on glibc >= 2.25), for comparison.
    for (auto _ : state) {
        benchmark::DoNotOptimize(::GetPID());
    }
}

BENCHMARK(BM_RawGetPid);

////////////////////////////////////////////////////////////////////////////////

} // namespace
} // namespace NYT