[Tutor] Run Time Analysis With Python
Ricardo Grant
rgrant at posteo.net
Wed Oct 2 11:37:58 EDT 2019
I am trying to learn more about performance analysis using python. I
made a small script to extract titles and uri's from Firefox's bookmark
JSON dump. Here is the script:
#!/usr/bin/python3
import json
bookmarks = json.load(open('/home/ricardo/bookmarks-2019-08-20.json'))
def descend(dict):
if 'children' in dict:
for child in dict['children']:
if 'uri' in child:
print('{} {}'.format(child['title'], child['uri']))
else:
descend(child)
and the profiling information
103 function calls (92 primitive calls) in 0.000 seconds
Ordered by: standard name
ncalls tottime percall cumtime percall filename:lineno(function)
1 0.000 0.000 0.000 0.000 <string>:1(<module>)
12/1 0.000 0.000 0.000 0.000 bookmarks.py:8(descend)
1 0.000 0.000 0.000 0.000 {built-in method
builtins.exec}
44 0.000 0.000 0.000 0.000 {built-in method
builtins.print}
1 0.000 0.000 0.000 0.000 {method 'disable' of
'_lsprof.Profiler' objects}
44 0.000 0.000 0.000 0.000 {method 'format' of 'str'
objects}
Due to it's recursive nature and my limited understanding of big O
analysis, I can't really find the steps to define a function that
describes the performance of this script. I would appreciate some hints
or even an explanation. Can you explain the profiling information as well?
I am also curious about my implementation. Does this code suffice, or is
there other ways to recurse into dictionaries?
More information about the Tutor
mailing list