diff options
author | Devtools Arcadia <arcadia-devtools@yandex-team.ru> | 2022-02-07 18:08:42 +0300 |
---|---|---|
committer | Devtools Arcadia <arcadia-devtools@mous.vla.yp-c.yandex.net> | 2022-02-07 18:08:42 +0300 |
commit | 1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch) | |
tree | e26c9fed0de5d9873cce7e00bc214573dc2195b7 /library/cpp/threading/future/perf/main.cpp | |
download | ydb-1110808a9d39d4b808aef724c861a2e1a38d2a69.tar.gz |
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'library/cpp/threading/future/perf/main.cpp')
-rw-r--r-- | library/cpp/threading/future/perf/main.cpp | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/library/cpp/threading/future/perf/main.cpp b/library/cpp/threading/future/perf/main.cpp new file mode 100644 index 0000000000..5a0690af47 --- /dev/null +++ b/library/cpp/threading/future/perf/main.cpp @@ -0,0 +1,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"); +} |