python装饰器计算函数运行时间
来源:互联网 发布:debian软件安装位置 编辑:程序博客网 时间:2024/06/03 15:38
import timefrom functools import wrapsimport random def fn_timer(function): @wraps(function) def function_timer(*args, **kwargs): t0 = time.time() result = function(*args, **kwargs) t1 = time.time() print ("Total time running %s: %s seconds" % (function.func_name, str(t1-t0)) ) return result return function_timer@fn_timerdef random_sort(n): return sorted([random.random() for i in range(n)]) if __name__ == "__main__": random_sort(2000000)
参考:7 tips to Time Python scripts and control Memory & CPU usage
python装饰器
装饰器
0 0
- python装饰器计算函数运行时间
- 使用python装饰器计算函数运行时间
- python装饰器decorator之计算函数运行时间的例子
- Python限制函数运行时间,记录函数运行时间的装饰器
- Python计算函数的运行时间
- 函数运行时间计算
- 计算函数运行时间
- 计算函数运行时间
- Python程序运行时间计算
- Python计算程序运行时间
- Python计算程序运行时间
- Python计算程序运行时间
- python计算程序运行时间
- Python计算程序运行时间
- Python计算程序运行时间
- 计算某函数运行时间
- C计算函数运行时间
- 计算函数的运行时间
- mvc与三层结构区别
- Android Studio 集成SVN 整理
- java finalize()方法
- Intersection of Two Linked Lists
- Android得到Layout里的布局文件里的自定义组件
- python装饰器计算函数运行时间
- 在res/values下创建attrs.xml
- 解决win8系统下subst使用不正常的问题
- 【笔记】软件活动中的浪费
- 民族 sql
- shell 字符串截取
- 二叉树非递归
- 性能优化笔记
- Python logging官方文档链接