python 时间戳问题
# python 时间戳问题
- 跑程序的时候发现 _id 相同冲突
- 程序中 mongo_id 的生成有 timestamp 决定
- 于是测试:
import time
for i in range(20):
print(time.time())
a = time.time()
for i in range(10**8):
time.time()
print(time.time() - a)
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
结果:
1546937536.8363261
1546937536.8363261
1546937536.8363261
1546937536.8363261
1546937536.8372946
1546937536.8372946
1546937536.8372946
1546937536.8372946
1546937536.8372946
1546937536.8372946
1546937536.8372946
1546937536.8372946
1546937536.8372946
1546937536.8372946
1546937536.8372946
1546937536.8372946
1546937536.8372946
1546937536.8372946
1546937536.8372946
1546937536.8372946
9.680140972137451
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
emmm 经过与同事的机器的对比 短时间内
Windows 上时间戳是相同
mac 不同
似乎是系统 bug
各位要用时间戳做 id 的同学注意下
注意
1546937536.8363261
1546937536.8372946
时间不是连续的
time 的精度不同
编辑 (opens new window)
上次更新: 2024-01-10 16:01:00