cout or printf which of the two has a faster execution speed C++?

后端 未结 15 2824
旧时难觅i
旧时难觅i 2020-11-27 07:04

I have been coding in C++ for a long time. I always wondered which has a faster execution speed printf or cout?

Situation: I am designing a

15条回答
  •  情歌与酒
    2020-11-27 07:18

    Another Stack Overflow question addressed the relative speed of C-style formatted I/O vs. C++ iostreams:

    • Why is snprintf faster than ostringstream or is it?

    • http://www.fastformat.org/performance.html

    Note, however, that the benchmarks discussed were for formatting to memory buffers. I'd guess that if you're actually performing the I/O to a console or file that the relative speed differences would be much smaller due to the I/O taking more of the overall time.

提交回复
热议问题