r/programming • • May 25 '19

Making the obvious code fast

https://jackmott.github.io/programming/2016/07/22/making-obvious-fast.html
1.3k Upvotes

263 comments sorted by

View all comments

Show parent comments

3

u/swansongofdesire May 26 '19

C++'s runtime is C's runtime — plus some extra bits

I took the poster to be saying exactly the same thing - but since c++ is larger it will take a little longer to load.

Even if you don't use anything from it, the OS is going to do extra work loading the lib. If it's statically linked then there's going to be more disk loads or memory pages to set up. Marginal? Yes, but that's why they were talking in the order of a few ms.

1

u/acwaters May 26 '19 edited May 26 '19

The few extra bits of runtime that C++ has are supplied in separate libraries on most platforms and are usually linked dynamically, so they won't incur any up-front loading time; they'll only be lazily loaded when (if) they're actually used. The statically linked bits like libgcc are common to C and C++, so there'll be no difference there. While C++ does typically produce larger binaries than C (sometimes substantially so), the difference between loading a 6K binary and a 12K binary (say) is not going to be on the order of milliseconds; using the parent commenter's suggestion of time ./a.out, you won't even be able to measure it. (It's funny, but a few milliseconds is not marginal when we're talking about native code; it's actually an eternity!)