2016-05-17 回答

用python实现计时器功能,代码如下:

''' simple timing function.

this function prints out a message with the elapsed time from the

previous call. it works with most python 2.x platforms. the function

uses a simple trick to store a persistent variable (clock) without

using a global variable.

'''

import time

def dur( op=none, clock=[time.time()] ):

if op != none:

duration = time.time() - clock[0]

print '%s finished. duration %.6f seconds.' % (op, duration)

clock[0] = time.time()

# example

if __name__ == '__main__':

import array

dur()  # initialise the timing clock

opt1 = array.array('h')

for i in range(1000):

for n in range(1000):

opt1.append(n)

dur('array from append')

opt2 = array.array('h')

seq = range(1000)

for i in range(1000):

opt2.extend(seq)

dur('array from list extend')

opt3 = array.array('h')

seq = array.array('h', range(1000))

for i in range(1000):

opt3.extend(seq)

dur('array from array extend')

# output:

# array from append finished. duration 0.175320 seconds.

# array from list extend finished. duration 0.068974 seconds.

# array from array extend finished. duration 0.001394 seconds.

python 计时器模块_python 如何添加计时器相关推荐

  1. python argparse模块_Python argparse模块应用实例解析

    这篇文章主要介绍了Python argparse模块应用实例解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 简介 argparse是python ...

  2. python counter模块_python collections模块 计数器(counter)

    一.计数器(counter) Counter是对字典类型的补充,用于追踪值的出现次数. ps:具备字典的所有功能 + 自己的功能 把我写入的元素出现的多少次都计算出来 import collectio ...

  3. python log模块_Python日志模块-logging

    一.logging模块 日志的作用可以简单总结为以下3点: 1.程序调试 2.了解软件程序运行情况,是否正常 3.软件程序运行故障分析与问题定位 1.日志的等级 不同的应用程序所定义的日志等级可能会有 ...

  4. python manager模块_Python 并发模块

    Python 并发模块 multiprocessing 介绍 multiprocessing 是一个用与 threading 模块相似API的支持产生进程的包. multiprocessing 包同时 ...

  5. python timer模块_Python timeit模块的使用实践

    Python 中的 timeit 模块可以用来测试一段代码的执行耗时,如一个变量赋值语句的执行时间,一个函数的运行时间等. timeit 模块是 Python 标准库中的模块,无需安装,直接导入就可以 ...

  6. python io模块_python中的StringIO模块

    原博文 2015-10-23 15:21 − # python中的StringIO模块 标签:python StringIO --- > 此模块主要用于在内存缓冲区中读写数据.模块是用类编写的, ...

  7. python shelve模块_python常用模块之shelve模块

    python常用模块之shelve模块 shelve模块是一个简单的k,v将内存中的数据通过文件持久化的模块,可以持久化任何pickle可支持的python数据类型 我们在上面讲json.pickle ...

  8. python pp模块_Python模块--Pexpect

    探索 Pexpect,第 1 部分:剖析 Pexpect 概述 Pexpect 是 Don Libes 的 Expect 语言的一个 Python 实现,是一个用来启动子程序,并使用正则表达式对程序输 ...

  9. python日历模块_Python日历模块| firstweekday()方法与示例

    python日历模块 Python calendar.firstweekday()方法 (Python calendar.firstweekday() Method) firstweekday() m ...

最新文章

  1. EST | 系统评价污水样品中选定药物、非法药物及其代谢物的稳定性
  2. LinkExtractor
  3. 那些年Android黑科技③:干大事不择手段
  4. 微软也走先使用后收费的路子--创业企业扶植计划(Microsoft BizSpark™)
  5. AC_CHECK_LIB的工作原理
  6. 乒乓球十一分制比赛规则_乒乓球比赛规则:十一分制的五种变化和规律
  7. linux块设备缓存bcache
  8. C++从屏幕输入数字以空格分割,存入整型数组
  9. 再见了Antirez永远的Redis之神
  10. 字符串长度测量,大小比较
  11. 电脑黑屏只有鼠标箭头怎么修复 电脑开机黑屏的修复办法
  12. 使用chrome设置代理,果然还是linux 方便呢。想安装一个chrome的插件,通过命令设置代理。
  13. 图片信息查看软件 ExifTool GUI
  14. RK3588 VOP-SPLIT分屏模式介绍
  15. GIS--矢量数据,栅格数据,切片,瓦片,金字塔的概念
  16. 微信小程序获取用户昵称和头像
  17. 视频剪辑方法,在视频上添加图片或者视频
  18. STM32 OV7725 传感器
  19. php30pro移动电源,30分钟让P30 Pro近满血 华为超级快充移动电源评测:迄今最强“奶妈”...
  20. “可口可乐”的制作配方泄漏了!~囧~

热门文章

  1. Vue中使用luckyexcel插件开发在线表格编辑
  2. 电脑显卡4种接口类型(转)
  3. PCIe接口及其衍生接口大总结
  4. 斗图还要上微博找资源?微信小程序表情包了解一下
  5. 长虹、康佳、TCL、创维联手平板售服对抗洋品牌(系列报道)
  6. 服务器信号显示闪电,数显测电笔显示闪电的原因
  7. 解决真机安装的Ubuntu18.04开机慢,关机关不了的问题
  8. 解决Python+selenium 自动化测试打开浏览器自动关闭问题适用于(Chrome和Edge)
  9. 解决Firefox 的Adobe Flash更新问题。
  10. 蓝牙耳机哪个品牌最好?总结四大蓝牙耳机品牌排行榜