2004年05月18日 星期二 16:20
Hollo info: 咦咦咦!看来没有参加前段的游戏讨论,在下封装过计时的工具类, 再附上: 最简单的就是类似: self.stop-self.start 让时间对象自个儿算去! /******** [2004-05-18]16:19:28 ; info wrote: info at xichen.com> python-chinese,您好! info at xichen.com> 请问python里面如何求两个时间的差?谢谢各位。 info at xichen.com> 致 info at xichen.com> 礼! info at xichen.com> info info at xichen.com> info at xichen.com info at xichen.com> 2004-05-18 ********************************************/ -- Free as in Freedom Zoom.Quiet #=========================================# ]Time is unimportant, only life important![ #=========================================# sender is the Bat!2.02 CE -------------- next part -------------- # -*- coding: gbk -*- # file timer.py #/********************************* # \class timer # \brief 通用Python 程序运行计时器 # \version 1.0 04427 for 数码球游戏 # \author Zoom.Quiet ( zoomq at itcase.com) # \attention Released under GNU Lesser GPL library license # \par usage # \li 声明 :watch = timer() # \li 跑秒 :watch.start() # \li 计时 :watch.stop() # \note 只要将watch.start();watch.stop() 分别插入到想测试的代码前后就可以了! #*********************************/ import sys,os,string,time class timer: def __init__(self): self.log="" def __repr__(self):# 类自述定义 print("利用Python 内含time 模块进行代码计时!") return self.log def start(self): self.start= time.time() self.log += "\n run at:"+time.strftime(" %Y-%m-%d %X",time.localtime(self.start)) return self.log def stop(self): self.stop= time.time() self.log += "\n end at:"+time.strftime(" %Y-%m-%d %X",time.localtime(self.stop)) self.log += "\n 本次运行共用时 %s秒"% (self.stop-self.start) return self.log if __name__ == '__main__': # 自测试 watch = timer() if(watch): import CBfilter playCB = CBfilter.CBfilter() # imported by other programs as well watch.start() result = playCB.play(8) print(watch.stop()) #print result else: print("\"\"")
Zeuux © 2024
京ICP备05028076号