site  contact  subhomenews

Quick Hello World size comparison

August 15, 2022 — BarryK

This is fun, just wanted to see the size of binary executable generated by V, Nim and BaCon. In all three, it is a one-line program. Firstly, the results, stripped by "strip --strip-unneeded":

27KB - 35KB

V has a lot of dead weight, and there seems no way to make it lose any of that weight. It statically links a huge library.

Nim has choice of different garbage collectors, or none. "arc" is the simplest and gave the 27KB size, as did "none". The default is "refc", which gave a 35KB binary.

Here is an example with Nim:

# nim c -d:release --opt:size --mm:arc  helloworld.nim

This is using the Nim that I compiled in OE. Here is how I compiled with BaCon:

# bacon -d build -o "-O2" helloworld.bac

There are further optimizations that can be applied for both the Nim and BaCon compilers, as they both work in a similar way, generate C code then call the 'cc' compiler.

Was reading here about the "-d:danger" option, that removes all runtime safety checks:

So did this:

# nim c -d:danger --opt:size --mm:none  helloworld.nim

...fantastic! Not that I would do that in practice, as the safety features don't add much to the size.

Forum member williams2 let me know about this:

...Nim "Hello World" is progressively reduced in size, right down to 150 bytes.    

Tags: easy