Created
July 27, 2015 13:00
-
-
Save alessandrocucci/3f29367669744392c2a6 to your computer and use it in GitHub Desktop.
Script per misurare il tempo di esecuzione di una funzione
This file contains 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
"""Script per misurare il tempo di esecuzione di una funzione | |
""" | |
import time | |
def timeit(method): | |
def timed(*args, **kw): | |
ts = time.time() | |
result = method(*args, **kw) | |
te = time.time() | |
print '%r (%r, %r) %2.6f sec' % \ | |
(method.__name__, args, kw, te-ts) | |
return result | |
return timed | |
@timeit | |
def prova1(): | |
a = [x for x in range(1000)] | |
@timeit | |
def prova2(): | |
a = [x for x in xrange(1000)] | |
prova1() | |
prova2() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment