Created
September 1, 2017 17:12
-
-
Save tito/9714e53fd76fe08153f11d5aef1b80e0 to your computer and use it in GitHub Desktop.
Test widget instanciation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
from kivy.factory import Factory | |
from time import time | |
MAX_TIME = 2 | |
def time_bounded_perf(f): | |
def _time_bounded_perf(*args, **kwargs): | |
start = time() | |
count = 0 | |
while True: | |
f(*args, **kwargs) | |
count += 1 | |
diff = time() - start | |
if diff > MAX_TIME: | |
break | |
print("{!r}: {} iterations in {:.2f} milliseconds".format( | |
f.__name__, count, diff * 1000)) | |
return _time_bounded_perf | |
@time_bounded_perf | |
def widget_creation(cls=Factory.Widget): | |
wid = cls() | |
@time_bounded_perf | |
def label_creation(cls=Factory.Label): | |
wid = cls() | |
@time_bounded_perf | |
def button_creation(cls=Factory.Button): | |
wid = cls() | |
Factory.Widget() | |
Factory.Label() | |
Factory.Button() | |
widget_creation() | |
label_creation() | |
button_creation() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment