import time def func(): time.sleep(1) t0 = time.time() func() t1 = time.time() print(t1-t0) # 1.0004117488861084
time.sleep():设置程序休眠时间,单位:秒。
time.sleep()
time.time():返回当前系统时间距January 1, 1970, 00:00:00 (UTC)的时间差,单位:秒。
time.time()
January 1, 1970, 00:00:00 (UTC)
https://docs.python.org/3.8/library/time.html