From Jason Turner
Watch on YouTube

Summary

This episode explains why using std::endl for line breaks in C++ stream operations can significantly impact performance. Jason demonstrates that std::endl is equivalent to outputting a newline character ('\n') followed by a flush operation, which forces the OS to write buffered data to disk immediately. Through benchmarking, he shows that using std::endl can be up to 17 times slower than using simple newline characters when writing to files, as each flush operation interrupts the normal buffering behavior of streams.

Resources

Tags