开发者

Measuring process time of a multi-thread code in Python

开发者 https://www.devze.com 2023-03-16 12:54 出处:网络
I am running the following code try to measure how long my PG process finish, however, the \"toc-tic\" displays as soon 开发者_运维百科as the whole loop finish, is there any way that I can measure the

I am running the following code try to measure how long my PG process finish, however, the "toc-tic" displays as soon 开发者_运维百科as the whole loop finish, is there any way that I can measure the total time and time for individual thread? Thanks

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

Regards, Andy


Join the threads, before toc!

You can put the objects to a list, then call join on them!

before the for :

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

for pg in pglist:
  pg.join()

toc = time.clock()

print toc - tic
0

精彩评论

暂无评论...
验证码 换一张
取 消