测量字节码使用情况

发布于 2024-10-08 09:59:09 字数 147 浏览 0 评论 0原文

我正在寻找一种绝对方法来对 python 中执行的计算进行基准测试/测量。在 Java 中,可以计算给定指令集的字节码使用情况。我可以在 Python 中采用类似的方法吗?

我愿意接受用于测量执行的计算的替代建议,只要方差很小(例如,时间对运行代码的机器太敏感)。

I'm looking for an absolute method to benchmark/measure computations performed in python. In Java, it's possible to calculate the bytecode usage for a given set of instructions. Is there a similar approach I could take in Python?

I'm open to alternative suggestions for measuring computation performed so long as the variance is minimal (time for example, is far too sensitive to the machine the code is being run on).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

妞丶爷亲个 2024-10-15 09:59:09

查看 dis 模块

>>> import dis
>>> def x(a,b):
...     return a+b
... 
>>> dis.dis(x)
  2           0 LOAD_FAST                0 (a)
              3 LOAD_FAST                1 (b)
              6 BINARY_ADD          
              7 RETURN_VALUE  

Check out the dis module.

>>> import dis
>>> def x(a,b):
...     return a+b
... 
>>> dis.dis(x)
  2           0 LOAD_FAST                0 (a)
              3 LOAD_FAST                1 (b)
              6 BINARY_ADD          
              7 RETURN_VALUE  
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文