Is it more effecient to use std::cout once rather than multiple times to display the same amount of data?

c++, performance

Solution

Having it be a single statement could theoretically be faster as the compiler can rearrange the order of argument evaluation more freely. However, this is talking about 0.00000000000001% difference and is pointless. Don't care about this - the bottleneck is in the console itself.

Anyway, column alignment is really helpful for readability and so try this:

std::cout <<       "First char is " << char1;
std::cout << " and second char is " << char2;

Or this:

std::cout <<       "First char is " << char1
          << " and second char is " << char2;

(I prefer the first because I find it easier to format in my text editor).

Problem

For example, Would it be more memory efficient to display these variables like this: ``` std::cout << "First char is " << char1 << " and second char is " << char2; ``` rather than this: ``` std::cout << "First char is " << char1; std::cout << " and second char is " << char2; ``` Of course, I'm not literally worried about two lines of code.. But I'm trying to learn to write code more efficiently Thank you

Original source