def number_add(self, *args):#not tested yet
if len(self.player1dict) == len(self.imported_ideas) and len(self.player2dict) == len(self.imported_ideas):
self.debug.text = 'Your Results:'
self.scrollview.clear_widgets()
self.scrollview.add_widget(self.answer_label)
for i in self.imported_ideas:
self.totalsdict[i] = self.player1dict[i] + self.player2dict[i]
for i in self.totalsdict:
if self.totalsdict[i] == 20:
self.array_ans.append('You scored 20/20 for: ' + i)
elif self.totalsdict[i] >14:
self.array_ans.append('You scored very highly for: ' + i)
elif self.player1dict[i] > 5 and self.player2dict[i] >5 or self.totalsdict[i] >= 13:
self.array_ans.append('You scored highly for: ' + i)
else:
pass
'''for i in self.player1dict:
if (self.player1dict[i] + self.player2dict[i])== 20:
self.array_ans.append('You scored 20/20 for: ' + i)
elif (self.player1dict[i] + self.player2dict[i]) >14:
self.array_ans.append('You scored very highly for: ' + i)
elif self.player1dict[i] > 5 and self.player2dict[i] >5 or (self.player1dict[i] + self.player2dict[i]) >= 13:
self.array_ans.append('You scored highly for: ' + i)
else:
pass'''
else:
self.debug.text = 'error, dictionary lengths not right'
self.answer_label.text = "\n".join(self.array_ans) #a better method for presenting ideas
self.answer_label.height=(self.r+10)*self.answer_label.font_size
目前这两个词典大约有35个关键词:值对长
我一直在使用这个功能将两个玩家给出的分数加在一起并打印出结果。然而,在我的笔记本电脑上计算需要几秒钟,在Android手机上只需几分钟。为什么这么苛刻?
注释掉的方法同样慢
代码中是否存在一些效率低下的问题?
提前谢谢!
编辑我通过cProfiler运行该方法
ncalls tottime percall cumtime percall filename:lineno(function)
1 0.000 0.000 0.000 0.000 <string>:1(<module>)
2 0.000 0.000 0.000 0.000 __init__.py:478(_set_text)
5 0.000 0.000 0.000 0.000 clock.py:243(__call__)
2 0.000 0.000 0.000 0.000 dampedscroll.py:93(on_value)
2 0.000 0.000 0.000 0.000 label.py:163(_trigger_texture_update)
5 0.000 0.000 0.000 0.000 lang.py:1324(delayed_call_fn)
1 0.000 0.000 0.000 0.000 main.py:201(number_add)
4 0.000 0.000 0.000 0.000 scrollview.py:212(_get_vbar)
4 0.000 0.000 0.000 0.000 scrollview.py:239(_get_hbar)
1 0.000 0.000 0.000 0.000 scrollview.py:380(_set_viewport_size)
2 0.000 0.000 0.000 0.000 scrollview.py:383(on__viewport)
2 0.000 0.000 0.000 0.000 scrollview.py:446(_update_effect_widget)
2 0.000 0.000 0.000 0.000 scrollview.py:452(_update_effect_x_bounds)
2 0.000 0.000 0.000 0.000 scrollview.py:459(_update_effect_y_bounds)
2 0.000 0.000 0.000 0.000 scrollview.py:466(_update_effect_bounds)
2 0.000 0.000 0.000 0.000 scrollview.py:485(_update_effect_y)
1 0.000 0.000 0.000 0.000 scrollview.py:766(add_widget)
1 0.000 0.000 0.000 0.000 scrollview.py:777(remove_widget)
8 0.000 0.000 0.000 0.000 widget.py:204(__eq__)
1 0.000 0.000 0.000 0.000 widget.py:212(__self__)
1 0.000 0.000 0.000 0.000 widget.py:316(add_widget)
1 0.000 0.000 0.000 0.000 widget.py:373(remove_widget)
1 0.000 0.000 0.000 0.000 widget.py:392(clear_widgets)
1 0.000 0.000 0.000 0.000 widget.py:539(get_top)
1 0.000 0.000 0.000 0.000 widget.py:552(get_center_x)
2 0.000 0.000 0.000 0.000 widget.py:564(get_center_y)
9 0.000 0.000 0.000 0.000 {isinstance}
4 0.000 0.000 0.000 0.000 {len}
1 0.000 0.000 0.000 0.000 {method 'add' of 'kivy.graphics.instructions.Canvas' objects}
10 0.000 0.000 0.000 0.000 {method 'append' of 'list' objects}
2 0.000 0.000 0.000 0.000 {method 'bind' of 'kivy._event.EventDispatcher' objects}
1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}
1 0.000 0.000 0.000 0.000 {method 'join' of 'str' objects}
1 0.000 0.000 0.000 0.000 {method 'remove' of 'kivy.graphics.instructions.Canvas' objects}