import time def timer def tmp args kwargs time time res args kwargs pr

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import time
def timer(f):
def tmp(*args, **kwargs):
t = time.time()
res = f(*args, **kwargs)
print "time func: %f" % (time.time()-t)
return res
return tmp
@timer
def func1():
for i in xrange(10000):
s = '{}{}'.format(1, 2)
@timer
def func2():
for i in xrange(10000):
s = '{0}{1}'.format(1, 2)
func1() # time func: 0.003652
func2() # time func: 0.003862