#计算密集型
def count(x,y):
c = 0
while c < 6000000:
c += 1
x += 1
y += 1
#IO密集函数
def write():
f = open('test.txt','w')
for i in range(1000000):
f.write("hello world\n")
f.close()
def read():
f = open('test.txt')
lines = f.readlines()
f.close()
单线程cpu密集型
from test import *
import time
t = time.time()
for i in range(10):
count(1,1)
print("Line cpu:",time.time() - t) #7.5比多线程执行时间还短
单线程IO密集型
from test import *
import time
t =time.time()
for i in range(10):
write()
read()
print("Line io:",time.time() - t) #3.9
多线程cpu密集型
from test import *
import threading
import time
# 多线程cpu密集型
counts = []
t = time.time()
for x in range(10):
th = thre