Last active
February 19, 2016 15:40
-
-
Save voidabhi/f45f8494898f82fdf66c to your computer and use it in GitHub Desktop.
Benchmarking for python functions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
def print_numbers(n): | |
for i in xrange(n): | |
pass | |
class BM(object): | |
def __init__(self, name): | |
self.name = name | |
def __enter__(self): | |
self.start = time.time() | |
def __exit__(self, *args): | |
print("{0} took {1}".format(self.name, time.clock() - self.start)) | |
with BM('print_numbers'): | |
for i in xrange(10000000): | |
print_numbers(i) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment