[Reserved] do not understand this 24 strokes nirvana, not to mention you'll Python!

24 strokes nirvana do not understand this, do not say you'll Python!

Qu ink learn programming every day

First, the run-time analysis code

The first type, measure the time code to run

Ordinary method

img

Shortcut (jupyter environment)

img

The second type, a running average measure multiple codes

time

Ordinary method

img

Shortcut (jupyter environment)

img

The third type, by calling the function run-time analysis code

Ordinary method

img

img

Shortcut (jupyter environment)

img

A fourth type, time code to run in rows Analysis

Ordinary method

img

img

img

img

Shortcut (jupyter environment)

img

Second, speed up your look

5 type, rather than to find a set list

Low method

img

img

High-speed method

img

6 style, with matching look dict instead of two list

Low method

img

img

High-speed method

img

Third, speed up your circulation

Formula 7, instead preferably used for loop while loop

Low method

img

High-speed method

img

Formula 8, to avoid double counting in the loop body

Low method

img

High-speed method

img

Fourth, accelerate your function

Equation 9, instead of the recursive function by looping mechanism

Low method

img

High-speed method

img

Formula 10, the acceleration caching mechanism recursive functions

Low method

img

High-speed method

img

The first type 11, with acceleration Python function numba

Low method

img

image

High-speed method

img

Fifth, use standard library functions to accelerate

Of formula 12, using the acceleration count collections.Counter

Low method

img

High-speed method

img

Of formula 13, using the dictionary combined acceleration collections.ChainMap

Low method

img

img

High-speed method

img

Sixth, accelerate the use of higher-order functions

Formula 14, instead of using the map for deriving the acceleration of formula

Low method

img

High-speed method

img

Formula 15, instead of the filter used to derive the formula for acceleration

Low method

img

High-speed method

img

Seven, using numpy accelerated vectorization

Formula 16, instead of using the list np.array

Low method

img

High-speed method

img

Formula 17, instead of using np.ufunc math.func

Low method

img

High-speed method

img

Formula 18, if instead of using np.where

Low method

img

img

High-speed method

img

Eight, accelerate your Pandas

Formula 19, instead of using the csv file read excel file reader

Low method

img

High-speed method

img

20 type, use pandas multi-process tool pandarallel ****

Low method

img

img

High-speed method

img

Nine, to accelerate the use of Dask

Of formula 21, using the acceleration dask dataframe

Low method

img

High-speed method

img

Of formula 22, using accelerated dask.delayed

Low method

img

img

High-speed method

img

Ten, multi-threaded multi-process acceleration

23-style, multi-threaded application acceleration IO-intensive tasks

Low method

img

High-speed method

img

24 type, multi accelerate the process of CPU-intensive tasks

Low method

img

High-speed method

img

Guess you like

Origin www.cnblogs.com/trent-fzq/p/11205610.html