用python 计时器怎么做,
发布网友
发布时间:2022-04-26 22:52
我来回答
共3个回答
热心网友
时间:2022-04-18 03:01
用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 r( op=None, clock=[time.time()] ):
if op != None:
ration = time.time() - clock[0]
print '%s finished. Duration %.6f seconds.' % (op, ration)
clock[0] = time.time()
# Example
if __name__ == '__main__':
import array
r() # Initialise the timing clock
opt1 = array.array('H')
for i in range(1000):
for n in range(1000):
opt1.append(n)
r('Array from append')
opt2 = array.array('H')
seq = range(1000)
for i in range(1000):
opt2.extend(seq)
r('Array from list extend')
opt3 = array.array('H')
seq = array.array('H', range(1000))
for i in range(1000):
opt3.extend(seq)
r('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.
热心网友
时间:2022-04-18 04:19
from sys import argv
h = {"+":int.__add__,"-":int.__sub__,"*":int.__mul__,"/":int.__div__}
print rece(h[argv[2]],[int(argv[1]),int(argv[3])])
最简单的。。。
python test.py 3 * 9
27
热心网友
时间:2022-04-18 05:54
汗。
原来是计算器.....