【发布时间】:2016-05-17 11:29:14
【问题描述】:
我想在不同的时间安排一个文本“hello world”(形成一个列表),因为脚本已经开始了。最好的方法是什么?
这可能是错误的,但我到目前为止:
import time
times = [1.76493425, 3.10174059, 4.49576803, 10.99379224, 18.84178369] #at these times since onset of script, a text "hello world" should be printed
start = time.time()
def main():
for cuetime in times:
print ('hello world', ' - timing: ', cuetime, ' - now: ', time.time()- start)
yield viztask.waitTime(cuetime)
main()
这给了我:
('hello world', ' - timing: ', 1.76493425, ' - now: ', 0.0)
('hello world', ' - timing: ', 3.10174059, ' - now: ', 1.7699999809265137)
('hello world', ' - timing: ', 4.49576803, ' - now: ', 3.5379998683929443)
('hello world', ' - timing: ', 10.99379224, ' - now: ', 5.305999994277954)
('hello world', ' - timing: ', 18.84178369, ' - now: ', 7.075000047683716)
但我真正需要的是与“现在”时间相同的时间元素/项目,因为时间列表中的元素是相对于开始应该打印文本“hello world”的时间脚本。
【问题讨论】:
标签: python timing benchmarking