import threading
import time
ind=3
def single():
for j in range(ind):
for i in range(5000):
w=2*i
#print(w)
def s():
for i in range(5000):
w=2*i
#print(w)
def multi():
threa=[]
for j in range(ind):
t=threading.Thread(target=s)
threa.append(t)
for t in threa:
t.start()
for t in threa:
t.join()
if __name__ == '__main__':
dan_sum=0
multi_sum=0
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,dan_sum,multi_sum)
这个慢了10倍。如果加上在线程中加上print多线程就会快一些。