3 ms·
I made a website where you can measure these things in both time and instructions. It's not perfect because it's a VM, but at least you can see for yourself the
by fwsgonzo 7y ago
I made a website where you can measure these things in both time and instructions. It's not perfect because it's a VM, but at least you can see for yourself the horror show that is the first exception thrown. And also the bloat that exceptions add. I still use exceptions simply because they are part of the language, although sparingly. But I have a gut feeling that the implementation of C++ exceptions in the current compilers, and the ABI, is just subpar. It has to be, because nothing that isn't a context switch should be measured in hundreds of thousands of instructions.
See: https://droplet.fwsnet.net https://droplet.fwsnet.net
Just experiment with adding and removing exceptions, and compare it. It's shocking.
Hello world using printf:
Instruction count: 14988
Binary size: 345 KB
Hello world try->throw->catch (and printf):
Instruction count: 286926
Binary size: 397 KB
Hello world using std::cout:
Instruction count: 63502
Binary size: 888 KB
- ncmncm 7y agoYou are just measuring initialization time. The global "C" locale used by printf is statically initialized. With constexpr that could be done in a C++ library if anybody cared. Runtime spent initializing might matter for startup in an embedded system, but they tend not to use cout much. You could submit a PR constexpr-ing std::cout initialization.