bench_func returning None for all but the first benchmark

未关闭
#166 5 条评论 3 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@amritamishra01 已经在做这个了。

开始于 2025年11月18日。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
38/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
技术栈
python
领域
performance

调研方向

复现 benchmarks.py 中的示例,然后阅读 pyperf/_runner.py 中的 bench_func,以及 pyperf/_bench.py 和 pyperf/_manager.py 中的基准测试收集路径。确定 manager 进程和 worker 进程之间预期的返回契约,并使行为或文档保持一致,以便将报告的基准测试结果收集到 BenchmarkSuite 中。

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

描述

I'm trying to write a benchmark suite for several functions and use BenchmarkSuite to write the results to a json file. I have the following code (irrelevant parts removed):

import pyperf
import decimation_accel as dec
import decimation_accel_opt as opt


results_file = 'decimation.json'

runner = pyperf.Runner()


def main() -> None:

    small = alloc_args(1024)
    small10 = alloc_args(1024, rate=10)
    small100 = alloc_args(1024, rate=100)
    medium = alloc_args(1024 * 10)
    benchmarks: List[pyperf.Benchmark] = []


    benchmarks.append(runner.bench_func('dec.decimate_minmax(small) all', dec.minmax, *small))
    benchmarks.append(runner.bench_func('opt.decimate_minmax(small) all', opt.minmax, *small))
    benchmarks.append(runner.bench_func('dec.decimate_minmax(small10) all', dec.minmax, *small10))
    benchmarks.append(runner.bench_func('opt.decimate_minmax(small10) all', opt.minmax, *small10))
    benchmarks.append(runner.bench_func('dec.decimate_minmax(small100) all', dec.minmax, *small100))
    benchmarks.append(runner.bench_func('opt.decimate_minmax(small100) all', opt.minmax, *small100))
    benchmarks.append(runner.bench_func('dec.decimate_minmax(medium) all', dec.minmax, *medium))
    benchmarks.append(runner.bench_func('opt.decimate_minmax(medium) all', opt.minmax, *medium))

    print(benchmarks)

    suite = pyperf.BenchmarkSuite(benchmarks)  # filename='decimation.json')

    suite.dump(results_file)


if __name__ == "__main__":
    main()

However if I run this file, I get the following output:

[<Benchmark 'dec.decimate_minmax(small) all' with 1 runs>, None, None, None, None, None, None, None]
Traceback (most recent call last):
  File "benchmarks.py", line 60, in <module>
    main()
  File "benchmarks.py", line 54, in main
    suite = pyperf.BenchmarkSuite(benchmarks)  # filename='decimation.json')
  File "<REMOVED>/venv-local/lib/python3.8/site-packages/pyperf/_bench.py", line 639, in __init__
    self.add_benchmark(benchmark)
  File "<REMOVED>/venv-local/lib/python3.8/site-packages/pyperf/_bench.py", line 687, in add_benchmark
    name = benchmark.get_name()
AttributeError: 'NoneType' object has no attribute 'get_name'
Traceback (most recent call last):
  File "benchmarks.py", line 60, in <module>
    main()
  File "benchmarks.py", line 39, in main
    benchmarks.append(runner.bench_func('dec.decimate_minmax(small) all', dec.minmax, *small))
  File "<REMOVED>/venv-local/lib/python3.8/site-packages/pyperf/_runner.py", line 537, in bench_func
    result = self._main(task)
  File "<REMOVED>/venv-local/lib/python3.8/site-packages/pyperf/_runner.py", line 460, in _main
    bench = self._manager()
  File "<REMOVED>/venv-local/lib/python3.8/site-packages/pyperf/_runner.py", line 673, in _manager
    bench = Manager(self).create_bench()
  File "<REMOVED>/venv-local/lib/python3.8/site-packages/pyperf/_manager.py", line 232, in create_bench
    worker_bench, run = self.create_worker_bench()
  File "<REMOVED>/venv-local/lib/python3.8/site-packages/pyperf/_manager.py", line 131, in create_worker_bench
    suite = self.create_suite()
  File "<REMOVED>/venv-local/lib/python3.8/site-packages/pyperf/_manager.py", line 121, in create_suite
    suite = self.spawn_worker(self.calibrate_loops, 0)
  File "<REMOVED>/venv-local/lib/python3.8/site-packages/pyperf/_manager.py", line 107, in spawn_worker
    raise RuntimeError("%s failed with exit code %s"
RuntimeError: <REMOVED>/venv-local/bin/python failed with exit code 1

If I don't put the results in the list, then they all appear to run fine, but then I have no way to collect the results.

主要语言
Python
星标
967
派生
112
平均合并
5 天 8 小时
30 天内合并 PR
9

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

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

psf/pyperf 的其他 Issue

查看 psf/pyperf 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

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