发布于 5年前
Python 统计执行一段代码的耗时
以下代码片段使用时间库来计算执行一段代码的耗时。
import time
start_time = time.time()
# Code to check follows
a, b = 1,2
c = a+ b
# Code to check ends
end_time = time.time()
time_taken_in_micro = (end_time- start_time)*(10**6)
print(" Time taken in micro_seconds: {0} ms").format(time_taken_in_micro)