python编写多线程程序并测速
import threading
import time
ind=2
def single():
for j in range(ind):
for i in range(5000):
print(i*2)
def s():
for i in range(5000):
print(i*2)
def multi():
threa=[]
for j in range(ind):
threa.append(threading.Thread(target=s))
for t in threa:
t.start()
for t in threa:
t.join()
if __name__ == '__main__':
start=time.time()
single()
end=time.time()
sum=0
sum1=0
sum=end-start
start=time.time()
multi()
end=time.time()
sum1=end-start
print('single',sum,'multi',sum1)