Paip. performance tracking profile principles and architecture and essence python scanning with javaphp
Source: Internet
Author: User
Paip. performance tracking profile principles and architecture and essence python scanning with javaphp paip. performance tracking profile principles and architecture and nature-python scanning with java php
# Background
Get all input method phonetic alphabet conversion atiEnPH tool, always python performance on K, 7 k Records browsing K takes 30 minutes.
# Goals
When analyzing the performance of a program, it all comes down to answering four basic questions:
How fast is the program running?
Where is the speed bottleneck?
How much memory does the program use?
Where is the memory leakage?
Who references the leaked object?
# Tool cProfile, objgraph
Who references the leaked object? This can be seen through the object reference graph ..
The output of this command should be a PNG image and saved in/tmp/backrefs.png. it looks like this:
Back refrences
At the bottom of the box is the objects we are interested in. We can see that it is referenced once by the symbol x and referenced three times by list y. If x causes a memory leak, we can use this method to track all its references to check why it is not automatically released.
Looking back, objgraph allows us:
Display the first N objects occupying the python program memory
Displays which objects are deleted after a period of time.
Show all references to a given object in our script
# Test code
Import cProfile
# Print the analysis result directly to the console
CProfile. run ("mainx ()")
# Save the analysis results to the file, but the content is not readable... you need to call the pstats module to analyze the results.
# CProfile. run ("foo ()", "result ")
# You can also directly use the command line for operations
#> Python-m cProfile myscript. py-o result
Def convert2atiEnPn (phntc): #17.3 s 49tse
"" Æ k @ sentjueit> e @ k @ sen @ tju @ ei @ t
"""
R = ""
# Print ("o412 ")
# Print (map)
#100 test logx abt 3 s
# Logx ("phntc: ---" + phntc)
Li = SybalbeList (phntc) #7.6 s
# Logx ("syblist :---")
# Print_li (li)
For sbl in li:
# All saveval invoke time safeVal 5.6 s 446tse
# Todox gaicheng jude modul .. only 0.1 s
# Yuln... python d effecti jon fei resource l.
Myvowel = safeVal (map, sbl. vowel ,"")
Mycnst = safeVal (map, sbl. csnt ,"")
R = r + "@" + mycnst + "-" + myvowel
# Phntc = trim (phntc)
Return r
# First Test
157277 function cballs in 20.648 seconds
# Analysis result:
As you can see, python exceptions consume a lot of performance. if key in map is used instead of exceptions, performance consumption starts from 5s to 0.1 s.
Log consumption performance
# Java and php profile
Java jprofile,... php xdebug ..
Reference
About Python Profilers performance analyzer-btchenguang-blog .htm
Python performance analysis Guide-technical translation-Kaiyuan Chinese community .htm
Python-- -fussfuss1-chinaunixbok.htm
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.