Hello everyone , We know Python There are many acceleration techniques . Today's article , I've summed it up for you 24 individual , Check for defects and make up for omissions , Learn a new trick every day . Longer content , Recommended collection 、 Focus on .
part Python The skills come from the sharing of small partners in the fan group , Thank you . Want to join the little partner , At the end of the article, the adding method .
Trivial method
Quick way (jupyter Environmental Science )
The first 2 type : Measure the average time of code running multiple times
Trivial method
Quick way (jupyter Environmental Science )
The first 3 type : Analyze code run time by calling function
Trivial method
Quick way (jupyter Environmental Science )
The first 4 type : Analyze code run time by line
Trivial method
Quick way (jupyter Environmental Science )
The first 5 type : use set Instead of list Search for
Low speed method
High speed method
The first 6 type : use dict Not two list Matching search
Low speed method
High speed method
The first 7 type : priority of use for Cycle, not while loop
Low speed method
High speed method
The first 8 type : Avoid double counting in the loop body
Low speed method
High speed method
The first 9 type : Replace recursive functions with looping mechanisms
Low speed method
High speed method
The first 10 type : Use recursive caching mechanism to speed up functions
Low speed method
High speed method
The first 11 type : use numba Speed up Python function
Low speed method
High speed method
The first 12 type : Use collections.Counter Speed up the count
Low speed method
High speed method
The first 13 type : Use collections.ChainMap Speed up dictionary merging
Low speed method
High speed method
The first 14 type : Use np.array Instead of list
Low speed method
High speed method
The first 15 type : Use np.ufunc Instead of math.func
Low speed method
High speed method
The first 16 type : Use np.where Instead of if
Low speed method
High speed method
The first 17 type : Use np.ufunc Function instead of applymap
Low speed method
High speed method
The first 18 type : Use pre allocated storage instead of dynamic capacity expansion
Low speed method
High speed method
The first 19 type : Use csv**** File reading and writing instead of excel File read and write
Low speed method
High speed method
The first 20 type : Use pandas Multi process tools pandarallel
Low speed method
High speed method
The first 21 type : Use dask Speed up dataframe
Low speed method
High speed method
The first 22 type : Use dask.delayed Accelerate
Low speed method
High speed method
The first 23 type : Apply multithreading acceleration IO Intensive task
Low speed method
High speed method
The first 24 type : Apply multi process acceleration CPU Intensive task
Low speed method
High speed method
Welcome to reprint 、 Collection 、 Gain some praise and support !
At present, a technical exchange group has been opened , Group friends have exceeded 2000 people , The best way to add notes is : source + Interest direction , Easy to find like-minded friends