Python commonly used debugging code execution performance (time)

Don't talk nonsense, just start working

Install time library

pip install time

Circulation 1000 renderings

import time
start_time = time.time()
a = 1
b = 2
c = a + b

for ii in range(0,1000):
    print(ii)
end_time = time.time()
total_time = end_time - start_time
print("Time: ", total_time)

Effect picture
Insert picture description here
Cycle 1W effect picture

import time
start_time = time.time()
a = 1
b = 2
c = a + b

for ii in range(0,10000):
    print(ii)
end_time = time.time()
total_time = end_time - start_time
print("Time: ", total_time)

As shown
Insert picture description here

The above is the code debugging skills! Often useful code quality performance issues! Hope you all support!

Guess you like

Origin blog.csdn.net/weixin_37254196/article/details/108222719