配置文件 Python cProfile 与 unix 时间 [英] Profile Python cProfile vs unix time

查看:82
本文介绍了配置文件 Python cProfile 与 unix 时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在分析 python 代码;为什么它会在用户空间花费更多时间?

I am profiling a python code ; why does it spend more time in the user space ?

 
     user@terminal$ time python main.py 

     1964 function calls in 0.003 CPU seconds

Ordered by: 标准名称

Ordered by: standard name

ncalls tottime percall cumtime percall filename:lineno(function)1 0.000 0.000 0.003 0.003 :1()1 0.000 0.000 0.000 0.000 ConfigParser.py:218(init)1 0.000 0.000 0.001 0.001 ConfigParser.py:266(读取)30 0.000 0.000 0.000 0.000 ConfigParser.py:354(optionxform)1 0.000 0.000 0.000 0.000 ConfigParser.py:434(_read)15 0.000 0.000 0.000 0.000 ConfigParser.py:515(get)15 0.000 0.000 0.000 0.000 ConfigParser.py:611(_interpolate)15 0.000 0.000 0.000 0.000 ConfigParser.py:619(_interpolate_some)1 0.000 0.000 0.000 0.000 config.py:32(read_config_data)1 0.000 0.000 0.001 0.001 config.py:9(init)6 0.000 0.000 0.000 0.000 entity.py:108(add_to_filter)1 0.000 0.000 0.002 0.002 entity.py:24(init)1 0.001 0.001 0.002 0.002 entity.py:39(create_inverted_index)493 0.000 0.000 0.001 0.000 entity.py:80(美化)1 0.000 0.000 0.000 0.000 entity.py:84(create_bucket_lookup)1 0.000 0.000 0.000 0.000 main.py:15()2 0.000 0.000 0.000 0.000 main.py:18()1 0.000 0.000 0.003 0.003 main.py:23(main)1 0.000 0.000 0.000 0.000 main.py:9(get_bag_of_words)19 0.000 0.000 0.000 0.000 {内置方法组}34 0.000 0.000 0.000 0.000 {内置方法匹配}1 0.000 0.000 0.000 0.000 {isinstance}2 0.000 0.000 0.000 0.000 {len}28 0.000 0.000 0.000 0.000 {列表"对象的附加"方法}1 0.000 0.000 0.000 0.000 {文件"对象的关闭"方法}15 0.000 0.000 0.000 0.000 {'dict'对象的'copy'方法}1 0.000 0.000 0.000 0.000 {_lsprof.Profiler"对象的禁用"方法}15 0.000 0.000 0.000 0.000 {str"对象的查找"方法}19 0.000 0.000 0.000 0.000 {str"对象的isspace"方法}24 0.000 0.000 0.000 0.000 {'str'对象的'join'方法}49 0.000 0.000 0.000 0.000 {方法'str'对象的'lower'}20 0.000 0.000 0.000 0.000 {'file'对象的'readline'方法}6 0.000 0.000 0.000 0.000 {方法'替换''str'对象}24 0.000 0.000 0.000 0.000 {str"对象的rstrip"方法}47 0.000 0.000 0.000 0.000 {method 'split' of 'str' 对象}9 0.000 0.000 0.000 0.000 {str"对象的startswith"方法}1030 0.000 0.000 0.000 0.000 {'str'对象的'strip'方法}15 0.000 0.000 0.000 0.000 {'dict' 对象的'更新'方法}2 0.000 0.000 0.000 0.000 {文件"对象的写入"方法}10 0.000 0.000 0.000 0.000 {打开}2 0.000 0.000 0.000 0.000 {范围}3 0.000 0.000 0.000 0.000 {减少}

ncalls tottime percall cumtime percall filename:lineno(function) 1 0.000 0.000 0.003 0.003 :1() 1 0.000 0.000 0.000 0.000 ConfigParser.py:218(init) 1 0.000 0.000 0.001 0.001 ConfigParser.py:266(read) 30 0.000 0.000 0.000 0.000 ConfigParser.py:354(optionxform) 1 0.000 0.000 0.000 0.000 ConfigParser.py:434(_read) 15 0.000 0.000 0.000 0.000 ConfigParser.py:515(get) 15 0.000 0.000 0.000 0.000 ConfigParser.py:611(_interpolate) 15 0.000 0.000 0.000 0.000 ConfigParser.py:619(_interpolate_some) 1 0.000 0.000 0.000 0.000 config.py:32(read_config_data) 1 0.000 0.000 0.001 0.001 config.py:9(init) 6 0.000 0.000 0.000 0.000 entity.py:108(add_to_filter) 1 0.000 0.000 0.002 0.002 entity.py:24(init) 1 0.001 0.001 0.002 0.002 entity.py:39(create_inverted_index) 493 0.000 0.000 0.001 0.000 entity.py:80(beautify) 1 0.000 0.000 0.000 0.000 entity.py:84(create_bucket_lookup) 1 0.000 0.000 0.000 0.000 main.py:15() 2 0.000 0.000 0.000 0.000 main.py:18() 1 0.000 0.000 0.003 0.003 main.py:23(main) 1 0.000 0.000 0.000 0.000 main.py:9(get_bag_of_words) 19 0.000 0.000 0.000 0.000 {built-in method group} 34 0.000 0.000 0.000 0.000 {built-in method match} 1 0.000 0.000 0.000 0.000 {isinstance} 2 0.000 0.000 0.000 0.000 {len} 28 0.000 0.000 0.000 0.000 {method 'append' of 'list' objects} 1 0.000 0.000 0.000 0.000 {method 'close' of 'file' objects} 15 0.000 0.000 0.000 0.000 {method 'copy' of 'dict' objects} 1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects} 15 0.000 0.000 0.000 0.000 {method 'find' of 'str' objects} 19 0.000 0.000 0.000 0.000 {method 'isspace' of 'str' objects} 24 0.000 0.000 0.000 0.000 {method 'join' of 'str' objects} 49 0.000 0.000 0.000 0.000 {method 'lower' of 'str' objects} 20 0.000 0.000 0.000 0.000 {method 'readline' of 'file' objects} 6 0.000 0.000 0.000 0.000 {method 'replace' of 'str' objects} 24 0.000 0.000 0.000 0.000 {method 'rstrip' of 'str' objects} 47 0.000 0.000 0.000 0.000 {method 'split' of 'str' objects} 9 0.000 0.000 0.000 0.000 {method 'startswith' of 'str' objects} 1030 0.000 0.000 0.000 0.000 {method 'strip' of 'str' objects} 15 0.000 0.000 0.000 0.000 {method 'update' of 'dict' objects} 2 0.000 0.000 0.000 0.000 {method 'write' of 'file' objects} 10 0.000 0.000 0.000 0.000 {open} 2 0.000 0.000 0.000 0.000 {range} 3 0.000 0.000 0.000 0.000 {reduce}

完成

真正的 0m0.063s用户 0m0.050s系统 0m0.010s

real 0m0.063s user 0m0.050s sys 0m0.010s

虽然 cProfile 说只用了 0.003 秒,但为什么 unix (sys) 时间说它在 0.01 秒内运行?

While the cProfile says it took only 0.003 seconds, why is unix (sys) time saying it runs in 0.01 seconds?

推荐答案

time(1)是衡量整个过程的执行时间,而profiler不包括Python解释器启动时间、字节码编译时间等

time(1) is measuring the execution time of the whole process, whereas the profiler excludes Python interpreter startup time, bytecode compilation time, etc.

这篇关于配置文件 Python cProfile 与 unix 时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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