python中频繁的print到底能浪费多长时间
violet_ever_garden:
贡献一个DP:
无print耗时: 0.000503
有print耗时: 0.026556
(都不包含建立logger对象时间)
有logger耗时: 0.192846
logger+print: 0.232925
记录后每1000log一次,log时一行一行log: 0.232925
(log数组和一行一行log耗时一样)
open file and append each time: 1.476877
open file 每1000append一次,一行一行append: 0.007000
open file 每1000append一次,1000次合并成chunk: 0.004998
open file 每1000append一次,每次加在string后: 0.005000
(open file 每1000append一次情况下,每次列表数字1000次转化成str然后join 和 每次在列表中转化成str然后1000次join 和 一行一行转化成string然后append 和 每次在string+= 耗时相同)
open file 不关闭 每1000append一次: 0.003001
python中频繁的print到底能浪费多长时间
reven#1118:
用spyder试了下博主的10000以内print消耗两秒。没print时间太短没显示。加到100w才用了0.7s
python中频繁的print到底能浪费多长时间
木游 Wella:
感谢,解决了我的疑问。本地测试:有"print"时的耗时:0.976346
没有"print"时的耗时:0.000998,差别太大了
python中频繁的print到底能浪费多长时间
coolfun2008:
是标准IDLE shell的问题,用其他差别很少。
python中频繁的print到底能浪费多长时间
ellija:
你的机器是哪里出问题了吗,有"print"时的耗时:0.068003
没有"print"时的耗时:0.001022