aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/threading/future/perf/main.cpp
blob: 71e9e293de19d30be899724702891311cfdd5354 (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
#include <library/cpp/testing/benchmark/bench.h>
#include <library/cpp/threading/future/future.h>
 
#include <util/generic/string.h>
#include <util/generic/xrange.h> 
 
using namespace NThreading; 
 
template <typename T> 
void TestAllocPromise(const NBench::NCpu::TParams& iface) {
    for (const auto it : xrange(iface.Iterations())) {
        Y_UNUSED(it); 
        Y_DO_NOT_OPTIMIZE_AWAY(NewPromise<T>()); 
    } 
} 
 
template <typename T> 
TPromise<T> SetPromise(T value) {
    auto promise = NewPromise<T>(); 
    promise.SetValue(value); 
    return promise; 
} 
 
template <typename T> 
void TestSetPromise(const NBench::NCpu::TParams& iface, T value) {
    for (const auto it : xrange(iface.Iterations())) {
        Y_UNUSED(it); 
        Y_DO_NOT_OPTIMIZE_AWAY(SetPromise(value)); 
    } 
} 
 
Y_CPU_BENCHMARK(AllocPromiseVoid, iface) {
    TestAllocPromise<void>(iface); 
} 
 
Y_CPU_BENCHMARK(AllocPromiseUI64, iface) {
    TestAllocPromise<ui64>(iface); 
} 
 
Y_CPU_BENCHMARK(AllocPromiseStroka, iface) {
    TestAllocPromise<TString>(iface);
} 
 
Y_CPU_BENCHMARK(SetPromiseUI64, iface) {
    TestSetPromise<ui64>(iface, 1234567890ull); 
} 
 
Y_CPU_BENCHMARK(SetPromiseStroka, iface) {
    TestSetPromise<TString>(iface, "test test test");
}