簡體   English   中英

什么是“ get()”函數出現在Python(PyPy)上的配置文件中?

[英]What is 'get()' function appeared in profiling on Python (PyPy)?

我在PyPy 1.8上通過“ profile.py”對程序進行了分析。

import profile
profile.run('run()', filename)
import pstats
p = pstats.Stats(filename)
p.sort_stats('time').print_stats(10)

這是分析的輸出:

Fri May 25 06:40:26 2012    profile.output

         225308 function calls (220308 primitive calls) in 1832700302271.964 seconds

   Ordered by: internal time
   List reduced from 49 to 10 due to restriction <10>

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
    57000 15986440103363.266 280463861.463 15986440103363.266 280463861.463 :0(get)
     7000 5696817988322.265 813831141.189 5696817988322.265 813831141.189 :0(getattr)
     .....

這個結果表明“ get()”是程序的瓶頸。 但是我根本不知道'get()'函數。

什么是Python上的“ get()”函數?

看起來像字典在被分析的代碼中的某處使用。

get(key[, default])

Return the value for key if key is in the dictionary, else default. 
If default is not given, it defaults to None, so that this method 
never raises a KeyError.

請參見映射類型-dictPython字典get()方法

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM