修改之后还是会输出很多东西,我只要调用次数和所花时间
时间: 2024-02-29 10:51:33 浏览: 21
如果你只需要简单的函数调用次数和所花时间,可以使用以下代码:
```python
import cProfile
def UtiFml(A):
D = np.linalg.det(A)
def Min(A,i,j):
up = np.hstack((A[:i,:j],A[:i,j+1:]))
lo = np.hstack((A[i+1:,:j],A[i+1:,j+1:]))
N = np.vstack((up,lo))
return((-1)**(i+j))*np.linalg.det(N)
def tComatrice(A):
Comat = np.zeros((10,10))
tComat = np.zeros((10,10))
for i in range(10):
for j in range(10):
Comat[i,j] = Min(A,i,j)
for i in range(10):
for j in range(10):
tComat[i,j] = Comat[j,i]
return tComat
tComatrice = tComatrice(A)
return(1/D*(tComatrice))
# 使用 cProfile 进行性能分析
pr = cProfile.Profile()
pr.enable()
UtiFml(M)
pr.disable()
# 获取函数调用信息
stats = pr.getstats()
for stat in stats:
func_name = stat.code.co_name
ncalls = stat.callcount
tottime = stat.totaltime
print(f'{func_name}: {ncalls} calls, {tottime:.4f} seconds')
```
这样,你就可以只输出函数调用次数和所花时间了。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)