例如:
import datetime
begin = datetime.datetime.now()
結果 = process(lines)
end = datetime.datetime.now()
print('Time spent: {}
'.format(end-begin))
它報告:
花費的時間。 0:00:00.005437。
這是否意味著這個程序函式只需要0.005毫秒?這對我的代碼來說似乎太少了,因為它是相當重的處理。我的問題是,datetime.now()是用毫秒還是秒作為時間單位?
uj5u.com熱心網友回復:
一個datetime.datetime的差異導致一個datetime.timedelta實體
它的字串表示法是
def __str__(self) 。
mm, ss = divmod(self._seconds, 60)
hh, mm = divmod(mm, 60)
s = "%d:d:d" % (hh, mm, ss)
if self._days:
def plural(n)。
return n, abs(n) ! = 1 and "s" or "
s = ("%d day%s, " % plural(self._days)) s
if self._microseconds:
s = s ".d" % self._microseconds.
return s
格式是這樣的 小時:分鐘:秒。微秒
在你的案例中,這使得
5437microsecond5毫秒5毫秒0.005437秒 。
因此,200次的運行將構成一秒
uj5u.com熱心網友回復:
更多細節請參考官方檔案
https://docs.python.org/3/library/datetime.html
類 datetime.time
一個理想化的時間,獨立于任何特定的日子,假設每天都有正好246060秒。(這里沒有 "閏秒 "的概念。) 屬性:小時、分鐘、秒、微秒和tzinfo。
當我執行你的代碼時,我得到了這個結果
`import datetimebegin = datetime.datetime.now()
end = datetime.datetime.now()
print('Time spent: {} '.format(end-begin))`
O/P:花費的時間。0:00:00.000014
所以單位時間是毫秒,這對處理來說是綽綽有余的
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/312018.html
標籤:
上一篇:Pandas。在GroupBy物件上使用時,列的總和產生意外的負值或NaT
下一篇:安卓10不支持白名單插件
