Python_性能测试

使用pip安装Python扩展库memory_profiler

 from memory_profiler import profile

 @profile    #修饰器
def isPrime(n):
if n == 2:
return True
for i in range(2,int(n**0.5)+2):
if n%i == 0:
return False
return True isPrime(99999999999999999999999999999999) '''
Line # Mem usage Increment Line Contents
================================================
3 10.9 MiB 0.0 MiB @profile #修饰器
4 def isPrime(n):
5 10.9 MiB 0.0 MiB if n == 2:
6 return True
7 10.9 MiB 0.0 MiB for i in range(2,int(n**0.5)+2):
8 10.9 MiB 0.0 MiB if n%i == 0:
9 10.9 MiB 0.0 MiB return False
10 return True
'''
上一篇:java-基础练习题3


下一篇:Unity-WIKI 之 AllocationStats(内存分配)