0

私のコードに何か問題がありますか? 通常のリストとは対照的にdeque、モジュールから使用して単純な関数のタイミングをとると、100 倍のスピードアップが得られます。collections

>>> from collections import deque as dl
>>> import cProfile
>>> 
>>> def l(i):
...     l = ['0','1','2','3','4','5','6']
...     while i:
...         l.insert(0,'9')
...         i -= 1
... 
>>> def d(i):
...     l = dl('0123456')
...     while i:
...         l.appendleft('9')
...         i -= 1
... 
>>> cProfile.run('l(100000)')
         100004 function calls in 4.480 seconds

[...]

>>> cProfile.run('d(100000)')
         100004 function calls in 0.031 seconds

私のコードに問題がない場合、リストを使用する意味は何ですか? に完全に切り替えてみませんdequeか?

4

1 に答える 1