[FR] Register function using macro, write the loop part only

未关闭
#1,950 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
5/5
预计耗时
一周以上
新手友好度
25/100
Issue 类型
功能
描述清晰度
需要澄清
活跃度
停滞
技术栈
cpp
领域
performance

调研方向

首先检查现有的 BENCHMARK_F、BENCHMARK_DEFINE_F 和 BENCHMARK_CAPTURE 宏 API,以了解其注册和回调模式。确定所提议的更简单注册形式是否可行,同时不会失去对 benchmark::State 或 setup 和 teardown 方法的访问。完成的标准是:有一个达成一致的 API 设计,并为受支持的使用模式提供实现和覆盖。

由索引模型根据 Issue 内容生成。

描述

Hi. I was thinking about a way to register a test by writing as little as possible boilerplate and looking for something like:

BENCHMARK_SIMPLE(TestName) {
    // Benchmark subject
}

The downside that you have to write second } to at least end the function.
And as with BENCHMARK_F, you can't call methods afterwards.

BENCHMARK_DEFINE_SIMPLE(TestName) {
    // Benchmark subject
}

BENCHMARK_REGISTER_SIMPLE(TestName)->Setup(...)->Teardown(...);

Now we can call methods, but we have same thing as with BENCHMARK_DEFINE_F: you have to spell the name of the test twice. 100% no copypasta :smiling:

If we pass do as BENCHMARK_CAPTURE we will have an almost perfect solution.

BENCHMARK_SIMPLE_CAPTURE([](benchmark::State& state){

})->Setup(...)->Teardown(...);

But we still have state argument written out. Dang it. We could remove it, but then we won't be able to get/set data from/to state.

I'll leave it as it for now, what do you think? Is it useful and is possible?

主要语言
C++
星标
10.5k
派生
1.8k
平均合并
2 天 2 小时
30 天内合并 PR
31

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

google/benchmark 的其他 Issue

查看 google/benchmark 的全部 Issue

相似的 Issue

更多 C++ Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。