【问题标题】:How to measure the speed of a kivy app如何测量 kivy 应用程序的速度
【发布时间】:2017-06-24 06:08:08
【问题描述】:

如何测量我的 kivy 程序中某个代码的速度?

我有一个函数,它通过使用字典、图片和屏幕管理器添加十个屏幕,这需要 5 秒以上。我想知道,这个函数最慢的部分是什么。

line_profiler (described here) 听起来不错,但是如果我运行它,我的应用程序窗口将保持黑色,没有绘制任何小部件,因此我无法单击某些按钮。

最好的方法是什么?

【问题讨论】:

    标签: kivy


    【解决方案1】:

    试试 cProfile - 它会将所有函数调用转储到一个文件中,以便稍后查看...

    import cProfile
    
    class MyApp(App):
        def on_start(self):
            self.profile = cProfile.Profile()
            self.profile.enable()
    
        def on_stop(self):
            self.profile.disable()
            self.profile.dump_stats('myapp.profile')
    

    另见How can I profile a Kivy application?

    也就是说...如果您猜测哪个部分是最慢​​,您总是可以输入一些 time.time()打印以找出导致减速的确切原因

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-09-15
      • 2013-04-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-07-12
      • 1970-01-01
      相关资源
      最近更新 更多