pyinstrument會把代碼里運行耗時的部分給你找出來
- 使用
pip install pyinstrument
import time
from pyinstrument import Profiler
def sleep_time():
time.sleep(2)
print('end')
profiler = Profiler()
profiler.start()
"""
要運行的內容
"""
sleep_time()
profiler.stop()
print(profiler.output_text(unicode=True, color=True))