diff options
Diffstat (limited to 'library/cpp/yt/system/benchmarks/process.cpp')
| -rw-r--r-- | library/cpp/yt/system/benchmarks/process.cpp | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/library/cpp/yt/system/benchmarks/process.cpp b/library/cpp/yt/system/benchmarks/process.cpp new file mode 100644 index 00000000000..74b4b6b1e13 --- /dev/null +++ b/library/cpp/yt/system/benchmarks/process.cpp @@ -0,0 +1,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 |
