Standard library thickness (Rust, C and C++) for the hello world


This post is more like a fact than a question or searching for a help.

I have compared three “hello world” applications in Rust, C and C++, to learn profiling with valgrind utility.
I have found interesting thing: the number of “dl_lookup_x” calls vary very much in each application.


fn main() {
    println!("Hello world");


#include <iostream>

int main () {
    std::cout << "Hello world" << std::endl;
    return 0;


#include <stdio.h>

int main() {
    printf("Hello world\n");
    return 0;

C++'s callgrind top 2:

1,267,311  ???:_dl_lookup_symbol_x [/usr/lib/]
  837,745  ???:do_lookup_x [/usr/lib/]

Rust’s callgrind top 3:

180,784  ???:do_lookup_x [/usr/lib/]
142,171  ???:strcmp [/usr/lib/]
 81,277  ???:_dl_lookup_symbol_x [/usr/lib/]

C’s callgrind top 5-6:

25,015  ???:do_lookup_x [/usr/lib/]
19,282  ???:_dl_lookup_symbol_x [/usr/lib/]

It seems that the C++'s standard library is so thick that it requires more than a million of calls
for resolving symbols of the standard library. The rust requires more than 6x less amount of
symbol lookup, while C library is the thinnest one and requires nearly 6x calls less than Rust.
So, if the take C as 1, Rust takes 7.23, C++ takes 50.66 times more resolution calls than C for
the “hello world” using native language approach (iostream, stdio.h and println! macro).

What do you think? Are my assumptions correct?


Perhaps related to this thread


Also the FAQ goes into this a bit


Hmmm, interesting. I would suggest you add an assembly one that calls write only. Or, even, a bare metal one.