为什么python输出数据时间比C++长,python输出,C语言中, printf
为什么python输出数据时间比C++长,python输出,C语言中, printf
C语言中, printf("number\n") 比 printf("number") 、
C++中, std::cout << number << std::endl 比 std::cout << number 、
Python 中, print number 比 print number,
都要花上更多的时间,比如从一打印到一百万,
C中相差了7秒,C++ 5秒,Python 10秒(虽然python中后一种是把换行改成空格)。
请问为什么会这样?
默认情况下stdout是行缓冲的,没有换行的话,程序会尽量缓存,直到某个阈值(比如1024)为止。缓存减少了与IO设备的交互,所以显然速度会更快。如果你在运行的时候把输出重定向文件(文件默认是全缓冲),估计就看不出差别了。
编橙之家文章,
相关内容
- Python Scrapy startproject错误异常代码修改求助,scrapystar
- Python access数据库pywintypes.com_error是什么问题,,使用Py
- 如何优化python mongodb批量修改任务,pythonmongodb,有一千万
- Function Annotation在python 2.7中使用有什么注意事项?,ann
- python is引用对象返回结果为何不同,pythonis引用对象,
- 获取字典中的url报错No such file or directory什么问题,ur
- object.__setattr__和直接设置Python属性有什么不一样?,
- python中flask celery配置结构出错求解,flaskcelery,脚手架是
- Python beautifulsoup方法得到input中value的方式是什么?,,H
- python代码文件目录打包该怎么写,python怎么写,小白提问
评论关闭