3 comments

[ 3.6 ms ] story [ 20.6 ms ] thread
It's significantly smaller when I do it on my machine with an optimizer.

Interestingly, g++ compiles it to the exact same code if you remove all the crap that isn't the main with the cout printing a literal string.

Without and with some optimization i get this results.

g++ -o hello hello.cpp

objdump --disassemble hello | wc -l

289

With some optimization

g++ -o hello hello.cpp -O3 -fno-rtti -fno-exceptions -fmessage-length=0 -funroll-all-loops -fomit-frame-pointer -falign-loops=2 -falign-jumps=2 -falign-functions=2 ;

objdump --disassemble hello | wc -l

256

This looks like it was compiled with `-O0 -g`. It'll be a lot slimmer with `-O1` or even `-Os`.

Edit: In fact, GCC 4.6.1 compiles it down to two function calls and some stack operations - about 15 instructions in all.