kernprof -l -v test.py #输出示例: Wrote profile results to test.py.lprof # 可用python -m pstats test.py.lprof 调用 Timer unit: 1e-06 s Total time: 0.001966 s File: test.py Function: storedata at line 8 Line # Hits Time Per Hit % Time Line Contents ============================================================== 8 @profile 9 def storedata(): 10 1 26 26.0 1.3 data = np.arange(10) 11 1 8 8.0 0.4 label = map(str,range(10)) 12 1 759 759.0 38.6 datafile = h5py.File('store.h5','w') 13 1 544 544.0 27.7 datafile.create_dataset('data', data = data) 14 1 331 331.0 16.8 datafile.create_dataset('label', data = label) 15 1 297 297.0 15.1 datafile.close() 16 1 1 1.0 0.1 return 0 ## 输出说明: #Line #: The line number in the file. #Hits: The number of times that line was executed. #Time: The total amount of time spent executing the line in the timer's units. In the header information before the tables, you will see a line "Timer unit:" giving the conversion factor to seconds. It may be different on different systems. #Per Hit: The average amount of time spent executing the line once in the timer's units. #% Time: The percentage of time spent on that line relative to the total amount of recorded time spent in the function. #Line Contents: The actual source code. Note that this is always read from disk when the formatted results are viewed, not when the code was executed. If you have edited the file in the meantime, the lines will not match up, and the formatter may not even be able to locate the function for display.