multiprocessing
-
#好像对于print() multiprocessing 效果不明显,可能不是这么操作的
import multiprocessing as mp
import time
def job(a,d):
for i in range(10000000):
print(i,end="-")
if __name__ == '__main__':
st = time.time()
p1 = mp.Process(target=job,args=(1,2))
p1.start()
p1.join()
et = time.time()
print('\n',str(et-st))
#打印时间 62.38630533218384 s
#尝试单独使用print()
#用时 58.4396448135376 s
#import multiprocessing as mp
import time
def job(a,d):
for i in range(10000000):
print(i,end="-")
if __name__ == '__main__':
st = time.time()
#p1 = mp.Process(target=job,args=(1,2))
#p1.start()
#p1.join()
job(1,2)
et = time.time()
print('\n',str(et-st))
网友评论