Cprofile--python Performance analysis Tools

Source: Internet
Author: User
Tags for in range

Python comes with several performance Analysis modules: Profile, Cprofile, and Hotshot, all of which are basically the same way, nothing more than a pure Python or C-written module. This article describes cprofile.

Example

Import  Time def func1 ():     = 0    for in range (1000000):        + =  idef  Func2 ():    time.sleep (ten) func1 () Func2 ()

Run

del. py

Run results

Results analysis
Performed 6 functions, which cost a total of 10.138s, sorted by the name of the running function as the result output.

Run the script

del del. py

This module directly saves the profile results, which can be used to further analyze the output results and run

" import pstats; p=pstats. Stats (' del.out '); P.print_stats ()"

Result (Random)

You can set the sort by how much time it takes to sort

" import pstats; p=pstats. Stats (' del.out '); P.sort_stats (' time '). Print_stats ()"

Sort_stats supports the following parameters:

Calls, cumulative, file, line, module, name, NFL, Pcalls, Stdname, time

The Pstats module also supports interactive

Cprofile--python Performance analysis Tools

Related Article

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.