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模块 ...
随机推荐
- 使用 Markdown 写博客
后台设置(左侧边栏区找到-设置默认编辑器). 设置为 Markdown 后保存,即可在编辑新博客时生效.
- RabbitMQ消费端自定义监听(九)
场景: 我们一般在代码中编写while循环,进行consumer.nextDelivery方法进行获取下一条消息,然后进行消费处理. 实际环境: 我们使用自定义的Consumer更加的方便,解耦性更强 ...
- git本地文件提交
一.github在线上传文件夹 1.点击上传文件 2 .直接拖拽 直接拖拽即可上传文件夹及文件夹里面的文件.如果点击 choose your files 就只能上传单个文件. 二.通过git工具上传本 ...
- apache cgi 程序: End of script output before headers
测试linux Apache cgi程序: #include <stdio.h> int main(){ printf("abc"); ; } 目录:/var/www/ ...
- TypeScript快速笔记(二)
1) TypeScript中的判断语句,可以使用非0值代表true.如: function add1(a: number, b?:number): number{ // 注意b是可选参数 consol ...
- C# Oledb 连接Access数据库字符串
string connStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + dbFile + ";Persist ...
- VB 获取所有窗体菜单信息
VERSION 5.00 Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "COMDLG32.OCX&q ...
- Vue知识整理5:v-bind绑定属性(Class 与 Style 绑定)
通过v-bind实现Class 与 Style 绑定,方便调整属性的值
- spring的后置处理器——BeanPostProcessor以及spring的生命周期
后置处理器的调用时机 BeanPostProcessor是spring提供的接口,它有两个方法——postProcessBeforeInitialization.postProcessAfterIni ...
- 阶段1 语言基础+高级_1-3-Java语言高级_1-常用API_1_第1节 Scanner类_2-概述及其API文档
键盘输入的类 Scanner首字母是大写的S.说明这是一个类,并不是关键字.关键字都是小写的.这个类是jdk中已经提供好的 1.看包 2.构造方法. 3.方法 只要不是引用类型,就是基本类型