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))

Simple!

Related Posts:


No comments yet

Leave a Reply

Note: You can use basic XHTML in your comments. Your email address will never be published.

Subscribe to this comment feed via RSS