python时间测量
- 使用自定义装饰器测量时间
def test_time(func):
def inner(*args, **kw):
t1 = datetime.datetime.now()
print('开始时间:', t1)
func(*args, **kw)
t2 = datetime.datetime.now()
print('结束时间:', t2)
print('耗时: ', t2 - t1)
return inner
@test_time
def call():
a = list()
for i in range(1000 * 10000):
a .append(i)
输出结果:
开始时间: 2019-08-30 22:22:01.881215
结束时间: 2019-08-30 22:22:02.816677
耗时: 0:00:00.935462
- 使用cProfile
def func():
a2 = list()
for i in range(100000):
a2.append(i)
if __name__ == '__main__':
al = list()
for i in range(2000000):
al.append(i)
func()
ncalls tottime percall cumtime percall filename:lineno(function)
1 0.254 0.254 0.405 0.405 test.py:8()
1 0.009 0.009 0.013 0.013 test.py:8(func)
1 0.000 0.000 0.405 0.405 {built-in method builtins.exec}
2100000 0.142 0.000 0.142 0.000 {method 'append' of 'list' objects}
1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}
能够显示各种操作的耗时。
- 更直观的逐行代码时间测量line_profiler
没装成功。
python时间测量的更多相关文章
- Python时间与日期操作(datetime、time、calendar)
相关模块 模块 说明 time time是一个仅包含与日期和时间相关的函数和常量的模块,在本模块中定义了C/C++编写的几个类.例如,struct_time类 datetime datetime是一个 ...
- [python] 时间序列分析之ARIMA
1 时间序列与时间序列分析 在生产和科学研究中,对某一个或者一组变量 进行观察测量,将在一系列时刻 所得到的离散数字组成的序列集合,称之为时间序列. 时间序列分析是根据系统观察得到的时间序列数据, ...
- 浅谈Python时间模块
浅谈Python时间模块 今天简单总结了一下Python处理时间和日期方面的模块,主要就是datetime.time.calendar三个模块的使用.希望这篇文章对于学习Python的朋友们有所帮助 ...
- python时间处理之datetime
python时间处理之datetime 标签: pythondateimportstringc 2012-09-12 23:21 20910人阅读 评论(0) 收藏 举报 分类: Python系列( ...
- python 时间字符串与日期转化
python 时间字符串与日期转化 datetime.datetime.strptime(string, format) 根据指定的格式解析字符串为一个datetime类型.相当于datetime.d ...
- 玩转X-CTR100 l STM32F4 l 定时器时间测量
我造轮子,你造车,创客一起造起来!塔克创新资讯[塔克社区 www.xtark.cn ][塔克博客 www.cnblogs.com/xtark/ ] 本文介绍X-CTR100控制器 使用处理器内部硬件定 ...
- python时间日期字符串各种
python时间日期字符串各种 第一种 字符串转换成各种日期 time 库 # -*- coding: utf-8 -*- import time, datetime # 字符类型的时间 tss1 = ...
- Python 时间日历类型
# 时间日历 # time模块 # 提供了处理时间和表示之间转换的功能 # 获取当前时间戳 # 概念 # 从0时区的1970年1月1日0时0分0秒, 到所给定日期时间的秒数 # 浮点数 # 获取方式 ...
- python—时间与时间戳之间的转换
python-时间与时间戳之间的转换 对于时间数据,如2016-05-05 20:28:54,有时需要与时间戳进行相互的运算,此时就需要对两种形式进行转换,在Python中,转换时需要用到time模块 ...
随机推荐
- [洛谷2257]ZAP-Queries 题解
前言 这道题还是比较简单的 解法 首先将题目转化为数学语言. 题目要我们求的是: \[\sum_{i=1}^a\sum_{j=1}^b[gcd(i,j)=d]\] 按照套路1,我们将其同时除以d转换为 ...
- Otto
导入依赖:implementation 'com.squareup:otto:1.3.8'1定义一个类继承Bus,并且设置单列模式注册和声明订阅者发送事件,最后解除注册与EventBus相同Event ...
- fedora18 Cannot retrieve metalink for repository: fedora. Please verify its path and try again 解决方法
Cannot retrieve metalink for repository: fedora. Please verify its path and try again 解决方法 执行如下命令: s ...
- layer系列之弹层layer.prompt
layer官网:https://www.layui.com/doc/modules/layer.html layer在线调试:http://layer.layui.com/ 如何使用layer.pro ...
- SQL优化—nested loop优化
跑批时间段22:00-23:00,生成AWR报告 分析sql:SQL_ID='5hfw4smzs2pqw' 执行计划: SQL> select * FROM TABLE(DBMS_XPLAN. ...
- xml json mongo
w wuser@ubuntu:~/apiamzpy$ sudo pip install xmljson
- linux的find和grep区别?
为什么会把 grep和find 这两个命令拿在一起来讨论? 是因为他们之间有一个容易混淆的地方, [在我的记忆中] : -name ? 它是find的选项! 不是grep的选项! 实际上, find基 ...
- mongodb 语法小结
数据库 一个mongodb中可以建立多个数据库. MongoDB的默认数据库为"db",该数据库存储在data目录中. MongoDB的单个实例可以容纳多个独立的数据库,每一个都有 ...
- sorted()与sort()函数
1 sorted可以对series,ndarry,list类型进行排序 默认会从小到大进行排序 arr1 = np.array([1,2,3,4,44,3243,43,8678]) print(sor ...
- mysql新建表
CREATE TABLE table( id int(20) not null auto_increment primary key, //auto_increment当为空时自动补全,注意,类型应该 ...