如何衡量一个kivy应用程序的速度

时间:2017-06-24 06:08:08

标签: kivy

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

我有一个功能,通过使用dict,图片和屏幕管理器添加十个屏幕,这需要超过5秒。我想知道,这个函数中最慢的部分是什么。

[0, 10, 20, 30, 40, 50]described here)听起来不错,但如果我运行它,我的应用程序窗口会保持黑色,不会绘制任何小部件,因此我无法点击某些按钮。

哪种方法最好?

1 个答案:

答案 0 :(得分:0)

尝试 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()打印以确定究竟导致减速的原因