代码如下:
#!/usr/bin/python# -*- coding:UTF-8 -*-import timedef execute_time(func):def wrapper(*args, **kwargs):start_time = time.time()result = func(*args, **kwargs)end_time = time.time()print func.__name__, \'execute_time:\', end_time - start_timereturn resultreturn wrapper@execute_timedef factorial(n):return reduce(lambda x, y: x * y, range(1, n + 1))@execute_timedef xor(n):return reduce(lambda x, y: x * y, range(1, n + 1))if __name__ == \'__main__\':print factorial(10)print xor(1000)
执行结果: