Python: Determine profiling of Python programs
Python Basic: Exercise-51 with Solution
Write a Python program to determine profiling of Python programs.
Note: A profile is a set of statistics that describes how often and for how long various parts of the program executed. These statistics can be formatted into reports via the pstats module.
Sample Solution:-
import cProfile
def sum():
print(1+2)
cProfile.run('sum()')
========== RESTART: F:/Python_APSC/py-ex-basic-51.py ==========
3
145 function calls in 0.013 seconds
Ordered by: standard name
ncalls tottime percall cumtime percall filename:lineno(function)
1 0.000 0.000 0.013 0.013 <string>:1(<module>)
2 0.000 0.000 0.013 0.007 PyShell.py:1336(write)
1 0.000 0.000 0.013 0.013 py-ex-basic-51.py:2(sum)
21 0.000 0.000 0.000 0.000 rpc.py:150(debug)
3 0.000 0.000 0.013 0.004 rpc.py:213(remotecall)
3 0.000 0.000 0.000 0.000 rpc.py:223(asynccall)
3 0.000 0.000 0.013 0.004 rpc.py:243(asyncreturn)
3 0.000 0.000 0.000 0.000 rpc.py:249(decoderesponse)
3 0.000 0.000 0.013 0.004 rpc.py:287(getresponse)
3 0.000 0.000 0.000 0.000 rpc.py:295(_proxify)
3 0.000 0.000 0.013 0.004 rpc.py:303(_getresponse)
3 0.000 0.000 0.000 0.000 rpc.py:325(newseq)
3 0.000 0.000 0.000 0.000 rpc.py:329(putmessage)
2 0.000 0.000 0.010 0.005 rpc.py:551(__getattr__)
1 0.000 0.000 0.010 0.010 rpc.py:569(__getmethods)
3 0.000 0.000 0.000 0.000 rpc.py:57(dumps)
2 0.000 0.000 0.000 0.000 rpc.py:592(__init__)
2 0.000 0.000 0.003 0.002 rpc.py:597(__call__)
6 0.000 0.000 0.000 0.000 threading.py:1224(current_thread)
3 0.000 0.000 0.000 0.000 threading.py:213(__init__)
3 0.000 0.000 0.012 0.004 threading.py:261(wait)
3 0.000 0.000 0.000 0.000 threading.py:72(RLock)
3 0.000 0.000 0.000 0.000 {built-in method _struct.pack}
3 0.000 0.000 0.000 0.000 {built-in method _thread.allocate_lock}
6 0.000 0.000 0.000 0.000 {built-in method _thread.get_ident}
1 0.000 0.000 0.013 0.013 {built-in method builtins.exec}
6 0.000 0.000 0.000 0.000 {built-in method builtins.isinstance}
9 0.000 0.000 0.000 0.000 {built-in method builtins.len}
1 0.000 0.000 0.013 0.013 {built-in method builtins.print}
3 0.000 0.000 0.000 0.000 {built-in method select.select}
3 0.000 0.000 0.000 0.000 {method '_acquire_restore' of '_thread.RLock' objects}
3 0.000 0.000 0.000 0.000 {method '_is_owned' of '_thread.RLock' objects}
3 0.000 0.000 0.000 0.000 {method '_release_save' of '_thread.RLock' objects}
3 0.000 0.000 0.000 0.000 {method 'acquire' of '_thread.RLock' objects}
6 0.012 0.002 0.012 0.002 {method 'acquire' of '_thread.lock' objects}
3 0.000 0.000 0.000 0.000 {method 'append' of 'collections.deque' objects}
1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}
3 0.000 0.000 0.000 0.000 {method 'dump' of '_pickle.Pickler' objects}
2 0.000 0.000 0.000 0.000 {method 'get' of 'dict' objects}
3 0.000 0.000 0.000 0.000 {method 'getvalue' of '_io.BytesIO' objects}
3 0.000 0.000 0.000 0.000 {method 'release' of '_thread.RLock' objects}
3 0.000 0.000 0.000 0.000 {method 'send' of '_socket.socket' objects}
>>>
沒有留言:
張貼留言