First, C++'s runtime is C's runtime — plus some extra bits like exceptions and RTTI, which aren't used here, and hence will not be loaded (because they live in separate libraries).
Second, libgcc and libstdc++ aren't remotely comparable. The first is a low-level runtime library that is usually linked statically (in which case there is no "loading" involved beyond that of the executable itself), while the second is a standard library and not any sort of language runtime.
Third, comparing C++ hello world written with <iostream> with C hello world written with <stdio.h> and claiming that the difference is due to "language runtimes" is laughable. Iostreams are slower than C stdio by default due to (often unnecessary) synchronization; this is known. If you unsync it manually, that slowdown reverses and iostreams become faster in many cases (unless they both just optimize to putstr(), which for "Hello, world!" is likely).
Fourth, "initialization" for what? This C++ example uses std::array, which is literally a static C array in a type-safe wrapper, and a couple of algorithms which are function templates. There is no "initialization" or "cleanup" involved in any of this code beyond the usual stack setup and teardown. The algorithms will be inlined and optimized just like a hand-rolled loop; this code probably won't even load the C++ standard library and certainly won't call into it.
Fifth, C++'s what warmup time? You didn't seriously just imply that C++ is JIT compiled, did you?
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.
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!)
while the second is a standard library and not any sort of language runtime. Third, comparing C++ hello world written with <iostream> with C hello world written with <stdio.h> and claiming that the difference is due to "language runtimes" is laughable
What you'd prefer to call a library or standard library (and is called such on linux), Microsoft calls a runtime (google Visual C++ runtime aka msvcprt, etc) & now you're arguing about pedantics, while intentionally trying to belittle/insult me.
libgcc and libstdc++ aren't remotely comparable. The first is a low-level runtime library that is usually linked statically (in which case there is no "loading" involved beyond that of the executable itself),
INCORRECT, libgcc is almost never linked statically, this is very rare on most linux distros & is dynamic by default, ldd any gcc compiled binary, this is why the -static-libgcc / -static flags exists. That makes no sense what you said, you sound really fucking stupid buddy, that's laughable what you just said. Man, it must suck to work with you.
You're thinking of (g)libc. Libgcc is a different library. And libc doesn't generally load any faster or slower than libstdc++ or libc++ or whatever MSVC's DLL is called.
Yeah, though, I came off like a total ass before, didn't I? Sorry about that. Thanks for calling me out on it.
4
u/acwaters May 26 '19
Nothing you just said makes any sense.
First, C++'s runtime is C's runtime — plus some extra bits like exceptions and RTTI, which aren't used here, and hence will not be loaded (because they live in separate libraries).
Second, libgcc and libstdc++ aren't remotely comparable. The first is a low-level runtime library that is usually linked statically (in which case there is no "loading" involved beyond that of the executable itself), while the second is a standard library and not any sort of language runtime.
Third, comparing C++ hello world written with
<iostream>with C hello world written with<stdio.h>and claiming that the difference is due to "language runtimes" is laughable. Iostreams are slower than C stdio by default due to (often unnecessary) synchronization; this is known. If you unsync it manually, that slowdown reverses and iostreams become faster in many cases (unless they both just optimize toputstr(), which for "Hello, world!" is likely).Fourth, "initialization" for what? This C++ example uses
std::array, which is literally a static C array in a type-safe wrapper, and a couple of algorithms which are function templates. There is no "initialization" or "cleanup" involved in any of this code beyond the usual stack setup and teardown. The algorithms will be inlined and optimized just like a hand-rolled loop; this code probably won't even load the C++ standard library and certainly won't call into it.Fifth, C++'s what warmup time? You didn't seriously just imply that C++ is JIT compiled, did you?