py37 idle
>>> def cz():
start = time()
for i in range(100000):
datetime.now().strftime('%Y-%m-%d')
print(str(time()-start))
>>> cz()
0.7051491737365723
>>> def cz():
start = time()
for i in range(1000000):
datetime.now().strftime('%Y-%m-%d')
print(str(time()-start))
>>> cz()
6.9613728523254395
>>> def cz():
start = time()
for i in range(1000000):
a=1
print(str(time()-start))
>>> cz()
0.029921293258666992
>>> def cz():
start = time()
for i in range(10000):
with open('a.txt','w') as f:
f.write('c')
print(str(time()-start))
>>> cz()
6.401899814605713
简单的文件操作是获取时间并且格式化字符串的大约100倍,是普通赋值的约100*233倍