【问题标题】:Benchmarking the CPU time of a python program in Windows 64-bit在 Windows 64 位中对 python 程序的 CPU 时间进行基准测试
【发布时间】:2011-07-28 23:39:12
【问题描述】:

我需要获取我的 python 应用程序的 CPU 运行时间。

How to measure execution time of command in windows command line?

我早些时候遇到了上述线程并了解了timeit。但是,根据下载网站,timeit 在 64 位 Windows 中是不支持的。

http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=17657#top

time.clock() 在 Windows 中不提供 CPU 时间。

有没有简单的方法来获取我的 python 应用程序的 CPU 时间?

【问题讨论】:

  • 目的是什么?您真的需要 CPU 时间还是只想知道需要多长时间?有内置的 Python 工具,例如 timeitcProfile 模块,可以为您做到这一点。
  • 我需要 CPU 时间来测试两个独立程序的性能。你知道哪个模块可以报告进程时间吗?我知道 time.clock() 在 Unix 中给出了 CPU 时间,但在 Windows 中没有。

标签: python windows-7 benchmarking


【解决方案1】:

如果您这样做只是为了对代码进行分析或基准测试,请不要构建自己的代码,而是使用内置库。

http://docs.python.org/library/profile.html

【讨论】:

  • 谢谢,这正是我所需要的。
  • profile 文档明确指出:“注意分析器模块旨在为给定程序提供执行配置文件,不用于基准测试目的(为此,有timeit 以获得合理准确的结果)。“
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-12-25
  • 2016-03-19
  • 2010-10-19
  • 1970-01-01
  • 2010-09-13
  • 1970-01-01
相关资源
最近更新 更多