From 3ecf5fd9d64a7fa47d6ddc2b0e3f2391996ee8e0 Mon Sep 17 00:00:00 2001 From: Zhijian Jiang Date: Tue, 3 Dec 2024 12:29:06 -0800 Subject: [PATCH] explains how folly benchmark decides how many iterations to run and how to tune it Summary: I spent some time to figure this out and it should be beneficial to mention that in the doc Differential Revision: D66708725 --- folly/docs/Benchmark.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/folly/docs/Benchmark.md b/folly/docs/Benchmark.md index 2ddd2c8d814..4e3eab62588 100644 --- a/folly/docs/Benchmark.md +++ b/folly/docs/Benchmark.md @@ -61,8 +61,11 @@ about it. Sometimes the function itself would want to do that iteration---for example how about inserting `n` elements instead of 100 elements? To do the iteration internally, use `BENCHMARK` with two parameters. The second parameter is the number of iterations and is -passed by the framework down to the function. The type of the count is -implicitly `unsigned`. Consider a slightly reworked example: +passed by the framework down to the function (folly benchmark runs as many as +iterations until the time spent exceeds 0.1ms ([code pointer](https://github.com/facebook/folly/blob/main/folly/Benchmark.cpp#L196)). +To increase iterations, especially for high-latency methods, adjust the `bm_min_usec` flag ([code pointer](https://github.com/facebook/folly/blob/main/folly/Benchmark.cpp#L179) +and `bm_max_secs` flag([code pointer](https://github.com/facebook/folly/blob/main/folly/Benchmark.cpp#L106))) to allow higher time budget). +The type of the count is implicitly `unsigned`. Consider a slightly reworked example: ``` Cpp #include