轻量级分析工具,用于检测python代码中的性能瓶颈。
bn的Python项目详细描述
因此得名:bn-瓶颈。 你知道B键和N键连续快速打字很舒服。
用法:
bn('loop') for item in generator: bn('rabbit') # code of rabbit bn('turtle') # code of turtle bn('loop') if bn.total > 1.0: logging.info(bn)
结果:
TOTAL=22.2632, turtle=20.6403, rabbit=1.6209, loop=0.0020 # # This config is default in bn>=0.1.5: # Bn(total_key='TOTAL', format='{key}={seconds:.4f}', sep=', ') # OR: 22.2632 TOTAL 20.6403 turtle 1.6209 rabbit 0.0020 loop # # This config is default in bn<=0.1.4: # Bn(total_key='TOTAL', format='{seconds:>10.4f} {key}', sep='\n')
安装:
pip install bn
范围:
# Global "bn" is useful to profile cross-module without passing "bn" explicitly. from bn import bn bn.format = custom_format # Scoped "Bn" is useful to have multiple independent profilers. from bn import Bn def action(): bn = Bn(format=custom_format)