1. Application analysis of cProfile module (chemical performance analysis)
The cProfile module is a more commonly used profiler. Combined with Gprof2Dot to convert the analyzer output into an image representation that can be processed by Graphviz, we can share the relevant information from the graph to get the time distribution information consumed by different functions.
- fighting.py
import random
def randomlist(n):
lists = []
l = [random.random() for i in range(n)]
l.sort()
for v in l:
lists.append(v)
return lists
if __name__ == "__main__":
randomlist(20)
Execute the analysis code:
python -m cProfile -s cumulative fighting.py
Description of related parameters:
- ncalls: Indicates the number of function calls;
- tottime: Indicates the total running time of the specified function, excluding the running time of calling sub-functions in the function;
- percall: (the first percal