• 使用自定义装饰器测量时间

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时间测量的更多相关文章

  1. Python时间与日期操作(datetime、time、calendar)

    相关模块 模块 说明 time time是一个仅包含与日期和时间相关的函数和常量的模块,在本模块中定义了C/C++编写的几个类.例如,struct_time类 datetime datetime是一个 ...

  2. [python] 时间序列分析之ARIMA

    1 时间序列与时间序列分析 在生产和科学研究中,对某一个或者一组变量  进行观察测量,将在一系列时刻  所得到的离散数字组成的序列集合,称之为时间序列. 时间序列分析是根据系统观察得到的时间序列数据, ...

  3. 浅谈Python时间模块

    浅谈Python时间模块 今天简单总结了一下Python处理时间和日期方面的模块,主要就是datetime.time.calendar三个模块的使用.希望这篇文章对于学习Python的朋友们有所帮助 ...

  4. python时间处理之datetime

    python时间处理之datetime 标签: pythondateimportstringc 2012-09-12 23:21 20910人阅读 评论(0) 收藏 举报  分类: Python系列( ...

  5. python 时间字符串与日期转化

    python 时间字符串与日期转化 datetime.datetime.strptime(string, format) 根据指定的格式解析字符串为一个datetime类型.相当于datetime.d ...

  6. 玩转X-CTR100 l STM32F4 l 定时器时间测量

    我造轮子,你造车,创客一起造起来!塔克创新资讯[塔克社区 www.xtark.cn ][塔克博客 www.cnblogs.com/xtark/ ] 本文介绍X-CTR100控制器 使用处理器内部硬件定 ...

  7. python时间日期字符串各种

    python时间日期字符串各种 第一种 字符串转换成各种日期 time 库 # -*- coding: utf-8 -*- import time, datetime # 字符类型的时间 tss1 = ...

  8. Python 时间日历类型

    # 时间日历 # time模块 # 提供了处理时间和表示之间转换的功能 # 获取当前时间戳 # 概念 # 从0时区的1970年1月1日0时0分0秒, 到所给定日期时间的秒数 # 浮点数 # 获取方式 ...

  9. python—时间与时间戳之间的转换

    python-时间与时间戳之间的转换 对于时间数据,如2016-05-05 20:28:54,有时需要与时间戳进行相互的运算,此时就需要对两种形式进行转换,在Python中,转换时需要用到time模块 ...

随机推荐

  1. HDU 4348 SPOJ 11470 To the moon

    Vjudge题面 Time limit 2000 ms Memory limit 65536 kB OS Windows Source 2012 Multi-University Training C ...

  2. TCP学习笔记

    TCP/IP 协议分层模型 TCP/IP 协议族按层次分别分为以下 4 层:应用层.传输层.网络层和数据链路层.层次化之后,每个层级只需要考虑自己的任务就可以了,不再需要弄清其他层级的功能了. TCP ...

  3. 小程序中css3实现优惠券

    效果如下: css3实现优惠券 知识储备 颜色渐变 linear-gradient() css伪类 :before :after index.wxss .app { /* padding: 20rpx ...

  4. 前端开发学习笔记 - 1. Node.JS安装笔记

    Node.JS安装笔记 Node.js® is a JavaScript runtime built on Chrome's V8 JavaScript engine. Node.js uses an ...

  5. 13-1 jquery操作cookie

    jQuery之cookie操作 Cookies 定义:让网站服务器把少量数据存储到客户端的硬盘或内存,从客户端的硬盘里读取数据的一种技术; 下载与引入:jquery.cookie.js基于jquery ...

  6. Android单行跑马灯效果实现

    参考网址:https://www.jianshu.com/p/e6c1b825d322 起初,使用了如下XML布局: <TextView android:id="@+id/tv_per ...

  7. jQuery UI Widget Factory

    https://learn.jquery.com/jquery-ui/widget-factory/ The jQuery UI Widget Factory is an extensible bas ...

  8. centos php 安装 decrypt

    CentOS php Fatal error: Call to undefined function mcrypt_decrypt() // yum安装没有 #yum install libmcryp ...

  9. windows10下安装docker报错:error during connect

    详细报错信息如下: C:\Users\zig>docker info error during connect: Get http://%2F%2F.%2Fpipe%2Fdocker_engin ...

  10. Java面试中hashCode()与equals(Object obj)方法关系的准确回答

    原文地址: https://blog.csdn.net/qq_19260029/article/details/77917925 hashCode()与equals(Object obj)都是Java ...