aboutsummaryrefslogtreecommitdiffstats
path: root/util/system/benchmark/create_destroy_thread/main.cpp
blob: 8f9f5c9850d57e5d85503b10256e0957f82be989 (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(); 
    } 
}