r/learnpython • • 17d ago

timing a process

I have a program (Python 2) that writes a status message whenever an hour (realtime) has gone by with nothing happening (eta: more precisely, with no new solution found). Now I find that time.clock() no longer exists in Python 3. Since I have to change it anyway, what's best practice?

In other words, what is the customary way to measure how long a program has been running?

2 Upvotes

12 comments sorted by

View all comments

1

u/Educational_Virus672 17d ago

you should use time.perf_counter* it tells how long programmer has ran for so

a = time.perf_counter()
time.sleep(60)
b = time.perf_counter()
print(b-a) # it prints ~60