aboutsummaryrefslogtreecommitdiffstats
path: root/util/system/benchmark/create_destroy_thread/main.cpp
blob: ebafa960d222b38ff013ed9e213cc7620ac51c0a (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
#include <library/cpp/testing/benchmark/bench.h> 

#include <util/system/thread.h>

static void* DoNothing(void*) noexcept {
    return nullptr;
}

Y_CPU_BENCHMARK(CreateDestroyThread, iface) {
    for (size_t i = 0, iEnd = iface.Iterations(); i < iEnd; ++i) {
        NBench::Clobber();
        TThread t(&DoNothing, nullptr);
        Y_DO_NOT_OPTIMIZE_AWAY(t);
        NBench::Clobber();
    }
}

Y_CPU_BENCHMARK(CreateRunDestroyThread, iface) {
    for (size_t i = 0, iEnd = iface.Iterations(); i < iEnd; ++i) {
        NBench::Clobber();
        TThread t(&DoNothing, nullptr);
        t.Start();
        NBench::Escape(t.Join());
        NBench::Clobber();
    }
}