我试图找出为什么以下非常简单、最小的示例在我的 i7-5500U CPU、Windows 10 计算机上占用了大约 33% 的 CPU 使用率:
import time
import numpy as np
import scipy.linalg
import cProfile
class CPUTest:
def __init__(self):
self.running = True
def compute_stuff(self):
dims = 150
A = np.random.random((dims, dims))
B = scipy.linalg.inv(np.dot(A.T, A))
def run(self):
prev_time = time.time()
start_time = prev_time
while self.running:
time.sleep(0.3)
st = time.time()
self.compute_stuff()
et = time.time()
print 'Time for the whole iteration, inc. sleep: %.3f (ms), whereas the processing segment took %.3f (ms): ' % ((st - prev_time) * …Run Code Online (Sandbox Code Playgroud)