Performance Analysis of basic operations in python and python

Source: Internet
Author: User

Performance Analysis of basic operations in python and python


Computing performance analysis has a deep vocabulary-algorithm analysis, which focuses on the demand for running time and space. The description of the computing time is generally based on the Growth magnitude. The growth magnitude is a set of functions, and its progressive growth behavior is equivalent, expressed by large O.
O (1) <O (logb n) <O (n logb n) <O (n2) <O (n3) <O (cn)

 

The base in the logarithm algorithm is not important. The exponent algorithm is only applicable to small data problems.

 

In Python, the time for arithmetic operations is constant, but the increase in arithmetic operations for super-large integers is linear. Index operations are constant time, regardless of the data structure. As long as all operations in the loop body are linear time, The for loop that traverses the list or dictionary is linear time. If you use the same loop to add a string list, the running time is the second, so join is usually used for String concatenation.

 

Most string and element group operations are linear. Except for indexes and len, they are constant time. min and max are linear. The slice operation time is proportional to the output length, it is independent of the output size.

 

Most listing methods are linear. Generally, adding and deleting elements at the end are constant time and sorting is O (n logb n ). The in operator is linear search, and so is the count and find operations of strings.

 

Most dictionary operations and methods are constant time, but the Run Time of copy and update is linear. keys, values and items are linear. iterkeys, itervalues and iteritems are constant time, however, if the iterator is traversed, the loop is also linear.

 

I still remember a famous saying: "If there is only one data structure, use a hash table !"

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.