main.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #include <library/cpp/testing/benchmark/bench.h>
  2. #include <library/cpp/threading/future/future.h>
  3. #include <util/generic/string.h>
  4. #include <util/generic/xrange.h>
  5. using namespace NThreading;
  6. template <typename T>
  7. void TestAllocPromise(const NBench::NCpu::TParams& iface) {
  8. for (const auto it : xrange(iface.Iterations())) {
  9. Y_UNUSED(it);
  10. Y_DO_NOT_OPTIMIZE_AWAY(NewPromise<T>());
  11. }
  12. }
  13. template <typename T>
  14. TPromise<T> SetPromise(T value) {
  15. auto promise = NewPromise<T>();
  16. promise.SetValue(value);
  17. return promise;
  18. }
  19. template <typename T>
  20. void TestSetPromise(const NBench::NCpu::TParams& iface, T value) {
  21. for (const auto it : xrange(iface.Iterations())) {
  22. Y_UNUSED(it);
  23. Y_DO_NOT_OPTIMIZE_AWAY(SetPromise(value));
  24. }
  25. }
  26. Y_CPU_BENCHMARK(AllocPromiseVoid, iface) {
  27. TestAllocPromise<void>(iface);
  28. }
  29. Y_CPU_BENCHMARK(AllocPromiseUI64, iface) {
  30. TestAllocPromise<ui64>(iface);
  31. }
  32. Y_CPU_BENCHMARK(AllocPromiseStroka, iface) {
  33. TestAllocPromise<TString>(iface);
  34. }
  35. Y_CPU_BENCHMARK(SetPromiseUI64, iface) {
  36. TestSetPromise<ui64>(iface, 1234567890ull);
  37. }
  38. Y_CPU_BENCHMARK(SetPromiseStroka, iface) {
  39. TestSetPromise<TString>(iface, "test test test");
  40. }