我正在做一些 python 基准测试,我发现它比orrepeat(None)
快得多:while True
while 1
>>> def bench7():
... foo = 0
... a = time()
... for i in repeat(None):
... foo += 1
... if foo == 100000000:
... break
... b = time()
... print a, b, b-a
...
>>> def bench8():
... foo = 0
... a = time()
... while True:
... foo += 1
... if foo == 100000000:
... break
... b = time()
... print a, b, b-a
...
>>> bench7()
1326592924.41 1326592935.42 11.0051281452
>>> bench7()
1326592936.36 1326592947.48 11.1183578968
>>> bench8()
1326592951.47 1326592965.03 13.5640599728
>>> bench8()
1326592966.07 1326592979.6 13.5341670513`
while 循环的这种用法是我实际使用 while 循环的最后一件事。有什么理由可以使用我忽略的时间吗?