我已经使用以下代码显示结果和经过的时间以在 mod_wsgi 中找出结果。但是无论我尝试什么,我总是将经过的时间设为 0,即使我将时间四舍五入到纳秒。我现在该怎么做来计算差异?
#!D:/Python27/python
from wsgiref.simple_server import make_server
from cgi import parse_qs, escape
import time
import datetime
html = """
<html>
<body>
<h2>Sum of first n factorials</h2>
<form method="get" action="Sec1q10.py">
Number :<input type="text" name="t1">
<br> <input type="submit" value="Submit">
</form>
<br>
Result:%s<br>
Now:%s<br>
End:%s<br>
Time:%s
</body>
</html>"""
def application(environ, start_response):
d=parse_qs(environ['QUERY_STRING'])
now = int(round(time.time()*1000000))
n=d.get('t1',[''])[0]
i=1
p=1
s=0
while (i<=int(n)):
p = p*i
s =s+p
i = i+1
end= int(round(time.time()*1000000))
diff=end-now
status = '200 OK'
output = html % (s or 'Empty',now or 'Empty',end or 'Empty',diff or 'Empty')
response_headers = [('Content-type', 'text/html'),
('Content-Length', str(len(output)))]
start_response(status, response_headers)
return [output]
它显示的输出是如果我输入了数字 4:
Result:33
Now:1346520500489000
End:1346520500489000
Time:Empty
我还能用什么来找出经过的时间?