2011-07-01 65 views
1

我正在运行下面的代码尝试测量我的PG进程完成多长时间,但是,只要整个循环结束,就会显示“toc-tic”,是否有任何我可以测量单个线程的总时间和时间吗?由于在Python中测量多线程代码的进程时间

tic = time.clock() 
for i in range(0,2):   
    start = i * step 
    end = start + step 

    pg = PatternGenerator() 
    pg.counter = start 
    pg.pos = i 
    pg.data = lines[start:end] 

    pg.start() 

toc = time.clock() 

print toc - tic 

问候, 安迪

回答

1

加入线程,TOC之前!

你可以把对象放到列表中,然后调用它们加入!

前为:

pglist = [] 
... start the threads... 

for pg in pglist: 
    pg.join() 

toc = time.clock() 

print toc - tic