简体   繁体   中英

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

I profile my program by 'profile.py' on PyPy 1.8.

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

Here is output of profiling:

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)
     .....

This result shows that 'get()' is the bottlenecks of program. But I don't know 'get()' function at all.

What is 'get()' function on Python?

Looks like a dictionary is used somewhere in the code being profiled.

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.

See Mapping Types - dict and Python dictionary get() Method .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM