Skip to content

Instantly share code, notes, and snippets.

@whiteinge
Last active May 11, 2024 16:36
Show Gist options
  • Save whiteinge/662e8cd1d361003b34531d9ee3c94197 to your computer and use it in GitHub Desktop.
Save whiteinge/662e8cd1d361003b34531d9ee3c94197 to your computer and use it in GitHub Desktop.
File sizes for "hello world" in various comple-to-C and compile-to-binary languages
Default compiler settings used, unless noted otherwise. Host system is Fedora
x86_64. Linked libs produced via `ldd`.
Linked libs common to all below: linux-vdso libc ld-linux
Size Lang Specific libs Common libs
18K c - -
20K luastatic liblua libm libdl
22K vala libgobject libglib libffi libpcre libpthread
27K urweb liburweb_http liburweb libm libcrypto libssl libpthread libz libdl
31K dlang (ldc2) libphobos2-ldc-shared libdruntime-ldc-shared libm libgcc_s libc
31K vlang (-prod) - libm libpthread libdl
32K ada libgnat libdl libm libgcc_s
34K chicken libchicken libm libdl
36K kit - libm
37K dlang (gdc) libgphobos libgcc_s libm libc
41K C++ - libstdc++ libm libgcc
56K ecl libecl libgmp libgc libffi libpthread libdl libm libatomic_ops libgcc_s
70K zig (ReleaseSmall) - (not dynamic)
70K idris - libgmp libpthread libm
83K red libRedRT linux-gate libm libpthread libgdk_pixbuf-2.0 libcurl libgtk-3 libudev libglib libgobject libgmodule libgio libpng16 libjpeg libnghttp2 libidn2 libssh libpsl libssl libcrypto libgssapi_krb5 libldap liblber libbrotlidec libz libgdk-3 libpangocairo-1.0 libpango-1.0 libharfbuzz libcairo libpangoft2-1.0 libfontconfig libfribidi libcairo-gobject libatk-1.0 libepoxy libXi libX11 libatk-bridge-2.0 libcloudproviders libtracker-sparql-3.0 libwayland-client libXfixes libcap libgcc_s libpcre2-8 libffi libmount libselinux libunistring libkrb5 libk5crypto libcom_err libkrb5support libkeyutils libresolv libevent-2.1 libsasl2 libbrotlicommon libxkbcommon libwayland-cursor libwayland-egl libXext libXcursor libXdamage libXcomposite libXrandr libXinerama libthai libfreetype libgraphite2 libXrender libxcb libxcb-render libxcb-shm libpixman-1 libxml2 libatspi libdbus-1 libjson-glib-1.0 libsqlite3 libblkid libcrypt libdatrie libbz2 libXau liblzma libsystemd libzstd liblz4
92K polyml libpolyml libstdc++ libm libgcc_s libpthread libffi libgmp libdl
175K vlang - libm libpthread libdl
177K cakeml - -
208K mlton - libm libgmp
320K ocaml - libm libdl
374K rust - libgcc_s
549K nim - libdl
569K zig - (not dynamic)
594K janet - libm libdl librt libpthread
840K dlang (dmd) - libpthread libm librt libdl libgcc_s
1.2M mlton (static) - (not dynamic)
1.9M golang - (not dynamic)
2.1M chicken ("static") - libm libdl
2.6M roc - (not dynamic)
2.7M haskell - libm libgmp librt libdl libpthread
9.7M sbcl (compressed) - libdl libpthread libz libm
12M racket 8 (raco exe) - libpthread
38M sbcl - libdl libpthread libz libm
42M node-pkg - libdl librt libstdc++ libm libgcc_s libpthread
45M node-nexe - libdl libstdc++ libm libgcc_s libpthread
@swise0
Copy link

swise0 commented Mar 29, 2022

Rustlang ? 🙂

@swise0
Copy link

swise0 commented Mar 29, 2022

Zig lang ?

@whiteinge
Copy link
Author

Rustlang ? slightly_smiling_face

Added! I even had rustc installed so not sure why I didn't think to include it here. The binary is much, much bigger than I expected -- it's on par with some of the langs that bundle their own runtime. Compiled with default settings and no CLI flags so maybe I'm overlooking something. 🤷

@swise0
Copy link

swise0 commented Mar 29, 2022

Assembly ?

@whiteinge
Copy link
Author

Zig lang ?

Added. Definitely the smallest of the static builds.

@whiteinge
Copy link
Author

Assembly ?

haha. Contributions welcome. 😀

@MarioVieilledent
Copy link

For Zig, once compiled with the -O ReleaseSmall command, it's only 5 KB (tested for windows 64)

@whiteinge
Copy link
Author

whiteinge commented Aug 10, 2023

For Zig, once compiled with the -O ReleaseSmall command, it's only 5 KB (tested for windows 64)

Awesome. Added. On my system the smaller binary is 70K. (Followed this.) If I use -target x86_64-windows it is 4.5K. That platform difference is very interesting, so I added a note about the host system at the top. Thanks!

One other interesting thing is if I use this Hello World the binary is 75K. I did use that example originally so I also updated the Zig entry for without the ReleaseSmall flag which is now also slightly smaller.

@adsharma
Copy link

kotlin-native 1.8.21: 916K

real 5.25
user 7.22
sys 0.29

Insists on using a .kexe extension even if I do -o hello.

Compiler written in java and hence the startup penalty. Expects you to use a build tool also written in the Java/Kotlin ecosystem.
Not interested in writing the compiler itself using Kotlin Native (asked in 2021).

@adsharma
Copy link

Linked libs: libm libpthread libgcc_s

@whiteinge
Copy link
Author

Cool. Thanks for the addition. What system did you build those results on?

@Imperatorn
Copy link

Imperatorn commented Sep 28, 2023

Try a D hello world

[1] ldc2 -O -release -link-defaultlib-shared -betterC app.d // using extern(C)
[2] ldc2 -O -release -link-defaultlib-shared app.d // normal

dlang.org - LDC

import std.stdio : printf;

void main()
{
    printf("Hello world");
}

vs betterC

import core.stdc.stdio;

extern(C) void main()
{
    printf("Hello world");
}

I got it to 9-10k

@whiteinge
Copy link
Author

Very interesting. The different D compilers have pretty different file size and linked lib results. Updated. Thanks for the comment!

@Imperatorn
Copy link

Very interesting. The different D compilers have pretty different file size and linked lib results. Updated. Thanks for the comment!

You're welcome 😇

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment