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?


Author old Wow's paw Attilax iron, EMAIL: 1466519819@qq.com
Reprinted please indicate Source: http://blog.csdn.net/attilax

# 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

Ordered by: standard name

Ncalltottime percall cumtime percall filename: lineno (function)
1 0.000 0.000 20.648 20.648 : 1 ( )
49 0.006 0.000 17.359 0.354 : 15 (convert2atiEnPn)
49 0.003 0.000 1.105 0.023 : 2 (updatexo4)
1 0.003 0.003 20.648 20.648 : 37 (mainx)

# Second:

118375 function cballs in 9.266 seconds

Ordered by: standard name

Ncalltottime percall cumtime percall filename: lineno (function)
1 0.000 0.000 9.265 9.265 : 1 ( )
49 0.002 0.000 6.395 0.131 : 15 (convert2atiEnPn)
49 0.003 0.000 1.155 0.024 : 2 (updatexo4)
1 0.004 0.004 9.265 9.265 : 39 (mainx)

# 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

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.