I was playing on https://godbolt.org/ and kinda wanted to check what assembly is produced when using std::println...
I was suprised that just for this really simple program, (compiled for x86_64):

#include <print> auto main() -> int { std::println("Hello World"); return 0; }

The binary generated by GCC (15.2, Trunk) and clang (21.1) are like 5000+ lines of assembly....
optimizer can't help. Would it be compiled with -O0 or -O3 the result is roughly the same....

When using iostream :

#include <iostream> auto main() -> int { std::cout << "Hello World" << std::endl; return 0; }

-> I get a binary of ~40 lines of assembly with -O3
-> I get a binary of ~15 lines of assembly with -O0.

I find all this really confusing...
I mean having a shorter binary with less optimization feels a bit off....
And having println generating 5000 lines of assembly seems a bit too much.
In fact i'm actually wondering if println is usable at all, then....

I know it's like 2 questions in the same post but all this confused me a lot....

Thanks in advance

wohlstad's user avatar

wohlstad

37.2k18 gold badges80 silver badges117 bronze badges

Koom's user avatar

16

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.