def performance(unit):
def f1(f):
@functools.wraps(f)
def f2(*args, **kw):
return f(*args, **kw)
return f2
return f1
def f1(f):
@functools.wraps(f)
def f2(*args, **kw):
return f(*args, **kw)
return f2
return f1
2015-03-03
def performance(unit):
def f1(f):
def f2(*args, **kw):
t1 = time.time()
r = f(*args, **kw)
t2 = time.time()
print 'call %s() in %s%s' % (f.__name__, (t1-t2), unit)
return r
return f2
return f1
def f1(f):
def f2(*args, **kw):
t1 = time.time()
r = f(*args, **kw)
t2 = time.time()
print 'call %s() in %s%s' % (f.__name__, (t1-t2), unit)
return r
return f2
return f1
2015-03-03
def count():
fs = []
for i in range(1, 4):
def f1(i):
def f2():
return i * i
return f2
fs.append(f1(i))
return fs
f1, f2, f3 = count()
print f1(), f2(), f3()
fs = []
for i in range(1, 4):
def f1(i):
def f2():
return i * i
return f2
fs.append(f1(i))
return fs
f1, f2, f3 = count()
print f1(), f2(), f3()
2015-03-03
def performance(f):
def fn(n):
t_start = time.time()
r = f(n)
t_stop = time.time()
print 'call ' + f.__name__ + '() in ' + str(t_stop - t_start)
return r
return fn
def fn(n):
t_start = time.time()
r = f(n)
t_stop = time.time()
print 'call ' + f.__name__ + '() in ' + str(t_stop - t_start)
return r
return fn
2015-03-03
def cmp_ignore_case(s1, s2):
if s1.lower() < s2.lower():
return -1
elif s1.lower() > s2.lower():
return 1
else:
return 0
print sorted(['bob', 'about', 'Zoo', 'Credit'], cmp_ignore_case)
if s1.lower() < s2.lower():
return -1
elif s1.lower() > s2.lower():
return 1
else:
return 0
print sorted(['bob', 'about', 'Zoo', 'Credit'], cmp_ignore_case)
2015-03-03