python - Python中的时间粒度
问题描述
在 Windows 10 下 Anaconda 提示下的 Python shell 中,以下程序:
a = datetime.datetime.now().timestamp()
b = a
n = 0
while b == a:
b = datetime.datetime.now().timestamp()
n +=1
print(n, a, b-a)
有时打印b-a
大约 1 毫秒,有时大约 15.61 毫秒。为什么是这样?
>>> exec(open("stamp.py").read())
602 1562500102.504166 0.015616178512573242
>>> exec(open("stamp.py").read())
640 1562500103.832325 0.015614986419677734
>>> exec(open("stamp.py").read())
788 1562500106.503157 0.0009992122650146484
>>> exec(open("stamp.py").read())
8270 1562500108.457863 0.015616893768310547
>>> exec(open("stamp.py").read())
6245 1562500113.863885 0.015617132186889648
>>> exec(open("stamp.py").read())
9032 1562500116.035434 0.015618085861206055
>>> exec(open("stamp.py").read())
2889 1562500117.547767 0.015616178512573242
>>> exec(open("stamp.py").read())
256 1562500119.647477 0.0010001659393310547
解决方案
推荐阅读
- sql - 如何使用时间戳类型数据制作程序
- android - Android Studio:蓝图区是做什么的?它有什么好处?
- linux - 在与特定文件大小匹配的目录中查找最新文件
- c# - 为什么带有 SharePointOnline CSOM 的 .NET Core 2.2 API 会抛出“进程没有包标识”?
- durandal-2.0 - 将 Durandal 子路线附加到主要路线对象
- python - 动态更改帧颜色 tkinter
- jquery - 缺少引导表排序图标
- google-apps-script - 复制工作表后,删除公式并保留值/格式
- sql-server - 通过调用其他存储过程向存储过程添加事务和回滚是否会按预期工作?
- google-bigquery - 使用 apache beam JsonTimePartitioning 在 bigqiery 中创建时间分区表