[BUG] Minimum benchmark time with multiple threads
维护者通常 1 天内回复
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 45/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 停滞
- 技术栈
- cpp
- 领域
- performance
调研方向
从处理 ThreadRange 基准测试的 --benchmark_min_time 以及 issue 中描述的 UseRealTime 行为开始。使用 --benchmark_min_time=1s 运行提供的 C++ 复现程序,并比较单线程和八线程的结果。完成标准是每个基准测试都为每个线程花费最少时间,并且线程数增加时迭代次数相应增加。
由索引模型根据 Issue 内容生成。
描述
Describe the bug
https://github.com/google/benchmark/pull/1836 fixed https://github.com/google/benchmark/issues/1834 and now the reported output makes more sense. However, the minimum benchmark time doesn't seem to be respected.
System
Arch Linux, GCC 15.2.1, benchmark 1.9.5-1
To reproduce
Consider
#include <benchmark/benchmark.h>
static void BM_MultiThreaded(benchmark::State& state) {
int a = 0;
for (auto _ : state) {
for (int i = 0; i < 1000; i++) {
benchmark::DoNotOptimize(a++);
}
}
}
BENCHMARK(BM_MultiThreaded)->ThreadRange(1, 8);
BENCHMARK_MAIN();
The output is somewhat expected:
---------------------------------------------------------------------
Benchmark Time CPU Iterations
---------------------------------------------------------------------
BM_MultiThreaded/threads:1 275 ns 274 ns 2585850
BM_MultiThreaded/threads:2 273 ns 272 ns 2259184
BM_MultiThreaded/threads:4 279 ns 278 ns 2449204
BM_MultiThreaded/threads:8 308 ns 307 ns 2148808
However, notice that the number of iterations stays constant - it should increase as more threads are used to run the iterations. For example:
$ /usr/bin/time -v ./benchmark-multithreaded --benchmark_min_time=1s --benchmark_filter=threads:8
[...]
User time (seconds): 1.72
Elapsed (wall clock) time (h:mm:ss or m:ss): 0:00.25
With previous versions of benchmark, this could be fixed with UseRealTime() but that doesn't seem to work anymore since (probably) https://github.com/google/benchmark/pull/1836.
Expected behavior
Each benchmark should spend the minimum time (per thread).
- 主要语言
- C++
- 星标
- 10.5k
- 派生
- 1.8k
- 平均合并
- 1 天 17 小时
- 30 天内合并 PR
- 30
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
google/benchmark 的其他 Issue
-
[BUG] Memory manager counts allocations not part of benchmark可能重新可做 关联的 PR 已关闭且未合并。 未关闭
难度 2/5 1-3 小时 新手友好度 68/100
google/benchmark#2149 · 5 条评论 ·
维护者通常 1 天内回复
-
[FR] Add native Zig bindings via top-level `bindings/zig`可能重新可做 关联的 PR 已关闭且未合并。 未关闭
难度 5/5 一周以上 新手友好度 42/100
google/benchmark#2266 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 4/5 3-5 天 新手友好度 48/100
google/benchmark#2235 · 2 条评论 ·
维护者通常 1 天内回复
-
难度 5/5 一周以上 新手友好度 20/100
google/benchmark#2195 · 3 条评论 ·
维护者通常 1 天内回复
-
难度 4/5 3-5 天 新手友好度 35/100
google/benchmark#2028 · 1 条评论 ·
维护者通常 1 天内回复
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 88/100
维护者通常 1 天内回复
-
bug test
难度 2/5 1-3 小时 新手友好度 82/100
OpenAssetIO/OpenAssetIO#1527 ·
-
难度 2/5 1-3 小时 新手友好度 66/100
ROCm/rocm-systems#15475 ·
维护者通常 2 天内回复
-
难度 1/5 1 小时以内 新手友好度 68/100
Sendspin/sendspin-cpp#257 ·
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 76/100
pocoproject/poco#5664 ·
维护者通常 2 天内回复