Python评测(PyPy)中出现的“get()”函数是什么?

2024-04-24 20:41:38 发布

您现在位置:Python中文网/ 问答频道 /正文

我的节目由'轮廓.py在PyPy1.8上。你知道吗

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()”函数是什么?你知道吗


Tags: to函数runimportgettimestatsfunction
1条回答
网友
1楼 · 发布于 2024-04-24 20:41:38

看起来在所分析的代码的某个地方使用了字典。你知道吗

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.

Mapping Types - dictPython dictionary get() Method。你知道吗

相关问题 更多 >