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 !"