Question

I've created a script which processes files and returns the size of each file in bytes. The time it takes is dependent on how large the directory is that you scan.

At the top of my script, I placed in:

now = "\n", strftime("%Y-%m-%d %H:%M:%S", gmtime())
print "Started processing data at:",now

and at the bottom:

finish = strftime("%Y-%m-%d %H:%M:%S", gmtime())
print "Finished processing data at: ", strftime("%Y-%m-%d %H:%M:%S", gmtime())
difference = now.strftime("%H:%M:%S", gmtime()) - finish.strftime("%H:%M:%S", gmtime())

I didn't think it was going to work, but I hope you understand my logic. I want to subtract the now hours, minutes & seconds from the finish hours, minutes & seconds.

What is the correct way of doing this?

Many thanks.

Was it helpful?

Solution

Try datetime module.

from datetime import datetime
start = datetime.now()

Later

difference = datetime.now() - start

OTHER TIPS

I would say to use something like:

import time
begin = time.time()
#your code here
end = time.time()
execution_time = end-begin
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top