main.cpp 1.4 KB

1234567891011121314151617181920212223242526
  1. #include <library/cpp/testing/benchmark/bench.h>
  2. #include <util/memory/pool.h>
  3. #include <util/generic/xrange.h>
  4. #include <util/stream/output.h>
  5. #define BENCHMARK_POOL_ALLOC(chunkSize, allocSize, allocAlign) \
  6. Y_CPU_BENCHMARK(MemroyPool_chunk##chunkSize##_alloc##allocSize##_align##allocAlign, p) { \
  7. TMemoryPool pool(chunkSize); \
  8. for (auto i : xrange<size_t>(0, p.Iterations())) { \
  9. (void)i; \
  10. Y_DO_NOT_OPTIMIZE_AWAY(pool.Allocate(allocSize, allocAlign)); \
  11. } \
  12. /* \
  13. Cerr << "Allocated: " << pool.MemoryAllocated() << Endl; \
  14. Cerr << "Waste: " << pool.MemoryWaste() << Endl; \
  15. */ \
  16. }
  17. BENCHMARK_POOL_ALLOC(4096, 1, 1)
  18. BENCHMARK_POOL_ALLOC(4096, 2, 2)
  19. BENCHMARK_POOL_ALLOC(4096, 3, 4)
  20. BENCHMARK_POOL_ALLOC(4096, 7, 8)
  21. BENCHMARK_POOL_ALLOC(4096, 17, 16)
  22. BENCHMARK_POOL_ALLOC(4096, 40, 64)
  23. BENCHMARK_POOL_ALLOC(4096, 77, 128)