Comparison of compilation results

Hi,

This is a question right out of curiosity - it is be no means meant as an implied criticism! :slight_smile:

Currently I am looking for a new programming language to work with (hobby). I cam across Zig and Nim.
When compiling code of Rosetta Code I found, that executables created with Zig and no optimization are about 10 times larger than those created with Nim.

What is the reason behing that?

PS: Currently I am using the latest and greatest repo-born zig 0.10 on Gentoo Linux.

Cheers!

Binary size, with or without optimization, is influenced by many factors that I believe are very particular to how each programming language works and the overall design philosophy of its developers. In the end, a final release build in both Nim and Zig should be pretty close in terms of binary size (after applying all available tricks to strip down to bare minimum.) So a decision in terms of which language to use will boil down to which language you like programming in the most; a matter of personal preference. I looked at Nim a while back and found it an impressive language. But I think its style is more familiar to Python programmers, whereas Zig is much more like C than anything else. But that’s my opinion here, so it’s up to what you find yourself more at home programming in.

Hi dude_the_builder,

I was asking, because I saw, that Zig supports building for a LOT of targets. One target is
the AVR line of microcontrollers, where the size of the resulting binary is important. I am a C
programmer far more than anything else. That’s why I choose Zig.

I see. While developing the Ziglyph library, I was seeing pretty big binary sizes even for release builds, then I discovered the strip option you can add to your build.zig and the size reduction was dramatic. Sample usage:

const exe = b.addExecutable("app", "src/main.zig");
exe.setTarget(target);
exe.setBuildMode(mode);
exe.strip = true;
exe.install();
3 Likes

Hi dude_the_builder,

Whow! Thanks for that information! Will help me a lot!

Cheers!
Tuxic

3 Likes