[BUG] Setup function running multiple times
- Dominant language
- C++
- Stars
- 10.4k
- Forks
- 1.8k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 8
Description
**Describe the bug**
According to the [user guide](https://github.com/google/benchmark/blob/8d86026c67e41b1f74e67c1b20cc8f73871bc76e/docs/user_guide.md?plain=1#L258=), global setup and teardown functions should be once, unless using multiple threads:
> The setup/teardown callbacks will be invoked once for each benchmark.
If the benchmark is multi-threaded (will run in k threads), they will be invoked exactly once before
each run with k threads.
However, I'm seeing the setup and teardown functions are being invoked multiple times as the framework determines its iteration count.
**System**
Which OS, compiler, and compiler version are you using:
- OS: Ubuntu 22.04
- Compiler and version: clang++ 14.0.0
- Benchmark version: `8d86026c67e41b1f74e67c1b20cc8f73871bc76e`
**To reproduce**
Steps to reproduce the behavior:
1. Follow the README to build _benchmark_
2. Add a single benchmark using the `BENCHMARK` macro, registering a setup function with `Setup`.
4. Add a print statement to your setup function
5. Run the benchmark single-threaded and see how often the setup function is called
**Expected behavior**
I'd expect the setup function is called once for each benchmark, not each time as the framework determines its iteration count.
Contributor guide
Assessment
This issue has not been assessed yet.