Skip to content

Instantly share code, notes, and snippets.

@alessandrocucci
Created July 27, 2015 13:00
Show Gist options
  • Save alessandrocucci/3f29367669744392c2a6 to your computer and use it in GitHub Desktop.
Save alessandrocucci/3f29367669744392c2a6 to your computer and use it in GitHub Desktop.
Script per misurare il tempo di esecuzione di una funzione
"""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