From bc857f03fc85a34e84ae8fcdf2d910259940f711 Mon Sep 17 00:00:00 2001 From: Jon Maltiel Swenson Date: Fri, 23 Oct 2015 14:44:22 -0700 Subject: [PATCH] Fibers allocation/deallocation benchmarks Summary: Add a couple benchmarks measuring allocation/deallocation latency. One benchmark measures an allocate-deallocate repeated pattern, the other measures the allocation of a large chunk of fibers. We'll use these benchmarks later on after we modify the allocation/deallocation behavior of fibers. Reviewed By: pavlo-fb Differential Revision: D2573064 fb-gh-sync-id: 414eb93d6223e42c187c03214a47dfb533491bab --- folly/experimental/fibers/test/FibersTest.cpp | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/folly/experimental/fibers/test/FibersTest.cpp b/folly/experimental/fibers/test/FibersTest.cpp index 6adf2831..874bf7df 100644 --- a/folly/experimental/fibers/test/FibersTest.cpp +++ b/folly/experimental/fibers/test/FibersTest.cpp @@ -1449,3 +1449,58 @@ BENCHMARK(FiberManagerBasicOneAwait, iters) { BENCHMARK(FiberManagerBasicFiveAwaits, iters) { runBenchmark(5, iters); } + +BENCHMARK(FiberManagerAllocateDeallocatePattern, iters) { + static const size_t kNumAllocations = 10000; + + FiberManager::Options opts; + opts.maxFibersPoolSize = 0; + + FiberManager fiberManager(folly::make_unique(), opts); + + for (size_t iter = 0; iter < iters; ++iter) { + EXPECT_EQ(0, fiberManager.fibersPoolSize()); + + size_t fibersRun = 0; + + for (size_t i = 0; i < kNumAllocations; ++i) { + fiberManager.addTask( + [&fibersRun] { + ++fibersRun; + } + ); + fiberManager.loopUntilNoReady(); + } + + EXPECT_EQ(10000, fibersRun); + EXPECT_EQ(0, fiberManager.fibersPoolSize()); + } +} + +BENCHMARK(FiberManagerAllocateLargeChunk, iters) { + static const size_t kNumAllocations = 10000; + + FiberManager::Options opts; + opts.maxFibersPoolSize = 0; + + FiberManager fiberManager(folly::make_unique(), opts); + + for (size_t iter = 0; iter < iters; ++iter) { + EXPECT_EQ(0, fiberManager.fibersPoolSize()); + + size_t fibersRun = 0; + + for (size_t i = 0; i < kNumAllocations; ++i) { + fiberManager.addTask( + [&fibersRun] { + ++fibersRun; + } + ); + } + + fiberManager.loopUntilNoReady(); + + EXPECT_EQ(10000, fibersRun); + EXPECT_EQ(0, fiberManager.fibersPoolSize()); + } +} -- 2.34.1