Skip to content

How to do time benchmarks in Python

2010 October 14
by Tedb0t

Say you’ve got a time-intensive script and you want to benchmark how long it takes—here’s a really simple and effective snippet.

from time import * #not best practice but... meh
startTime = time()

# super-complicated, time-consuming code

elapsed = time() - startTime
print "Finished. Total time: " + strftime('%H:%M:%S', gmtime(elapsed))


Related Posts:

Comments are closed.