cProfile の使用:
ncalls tottime percall cumtime percall filename:lineno(function)
1 0.000 0.000 17.834 17.834 <string>:1(<module>)
1 0.007 0.007 17.834 17.834 basher.py:5551(_refresh)
1 0.000 0.000 10.522 10.522 basher.py:1826(RefreshUI)
4 0.024 0.006 10.517 2.629 basher.py:961(PopulateItems)
211 1.494 0.007 7.488 0.035 basher.py:1849(PopulateItem)
231 0.074 0.000 6.734 0.029 {method 'sort' of 'list' objects}
215 0.002 0.000 6.688 0.031 bosh.py:4764(getOrdered)
1910 3.039 0.002 6.648 0.003 bosh.py:4770(<lambda>)
253 0.178 0.001 5.600 0.022 bosh.py:3325(getStatus)
1 0.000 0.000 5.508 5.508 bosh.py:4327(refresh)
1911 3.051 0.002 3.330 0.002 {method 'index' of 'list' objects}
その1910 3.039 0.002 6.648 0.003 bosh.py:4770(<lambda>)
線は私を困惑させます。bosh.py:4770 にはmodNames.sort(key=lambda a: (a in data) and data.index(a))
、 data と modNames がリストになっています。1911 3.051 0.002 3.330 0.002 {method 'index' of 'list' objects}
この行から来ているように見えることに注意してください。
では、なぜこれはとても遅いのでしょうか? これを書き直してsort()
、より高速に実行できる方法はありますか?
編集:このラムダを理解するために欠落していた最後の成分:
>>> True and 3
3