Python中导入所花费的时间 [英] Time taken by an import in Python

查看:126
本文介绍了Python中导入所花费的时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道导入对内置模块和用户定义模块需要多长时间。

I want to know how much time an import takes for both built-in as well as user defined modules.

推荐答案

分析导入的一种方法是使用bzr 源代码中使用的profile_imports模块:

One way to profile imports is to use the profile_imports module used in bzr source code:

# put those two lines at the top of your script
import profile_imports
profile_imports.install()

# display the results
profile_imports.log_stack_info(sys.stderr)

除此之外给你进口的时间,这也估计编译正则表达式的时间,这通常是进口放缓的重要原因。

Besides giving you timing for imports, this also estimates time to compile regex, which is often a significant cause for slowdown in imports.

这篇关于Python中导入所花费的时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆