0

How can I measure the speed of a certain code in my kivy program?

I've got a function, that adds ten screens by using a dict, pictures and screenmanager, and that takes more then 5 seconds. I would like to find out, what is the slowest part of this function.

line_profiler (described here) sounds good, but if I run it, my application window stays black, no widgets are drawed and so I couldn't click on some buttons.

Which are the best methods?

flowerflower
  • 327
  • 1
  • 3
  • 10

1 Answers1

0

Try cProfile - it will dump all the functions calls with times to a file to review later on...

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')

see also How can I profile a Kivy application?

That said... if you have a guess on which part is the slowest you can always put some time.time() prints to figure what exactly causes the slow-down

Yoav Glazner
  • 7,936
  • 1
  • 19
  • 36