Learning Zig via Ziglings

5/27/2026

Saw lots of videos online, mostly through the PrimeTime, talking about zig and it looks interesting to learn. The fact that it is a young language makes the learning very fun. Can’t rely too much on AI anymore. They hallucinate too much on this language, espcially about the latest version. Had to learn it the old school way: going through documentation and forums. Quite fun actually, feels like I am participating something that’s involving. Also because this language seem to be far away from what I do at work, feels like I wasn’t constently thinking about work. Helps recharge during the weekend…but needs to pay attention not to bring it directly into work or make it part of the work though.

As recommended by people, of course also by the PrimeTime, I started learning zig with ziglings. It’s quite amazing how ziglings breakdown the information into quiz and also walk through the concepts in comments throughout the code. Getting used to a high level language like Python, I almost never think about what kind of things needs to be done before using a variable. Not only have I been through some headaches in writing a couple of my first lines in zig wondering what type I should declare and how large should they be, I also was amazed by the things it can do with bit manipulation. I must’ve learnt it before in my long forgotten c++ class. But last weekend, I was so shocked how much you can do and actually use the bits to record information instead of always using a big chunk of bytes.

At a later investigation, my mentor has proven to me that gcc + c is very fast and produce very minimal binary, the compiler can be doing something very smart…the compiler is very nice to you and trust that you know what you are doing. It’s facinating how much he knows about these things work. So muh to learn in front of me. At the moment, I think I still need the safety that zig provides. Also I discover that zig compiler actually allows things to be compiled if you INSIST (i.e. releasefast). =)

======== some interesting and boring at the same time details from my experiment ========

when the program could overflow…and I force it to compile, still zcc is more verbose than gcc, but performance very close. u26 is slow as expected.

u32: zig build-exe u32.zig -fstrip -OReleaseFast -T linker.ld -femit-asm
u26: zig build-exe u26.zig -fstrip -OReleaseFast -T linker.ld -femit-asm
gcc_a.out: gcc -O3 main.c
zcc_a.out: zig cc -O3 main.c
706k 26 May 15:45 u32.s
706k 26 May 16:09 u26.s
1.3k 26 May 15:32 gcc_main.s
30k 26 May 15:32 zcc_main.s
crap -w 200 'u32' 'u26' 'gcc_a.out' 'zcc_a.out'
Benchmark 1 (2150 runs): u32
measurement mean ± σ min … max outliers delta
wall_time 2.32ms ± 133us 2.09ms … 3.62ms 135 ( 6%) 0%
peak_rss 1.51MB ± 612 1.51MB … 1.52MB 3 ( 0%) 0%
Benchmark 2 (2003 runs): u26
measurement mean ± σ min … max outliers delta
wall_time 2.49ms ± 108us 2.26ms … 3.33ms 93 ( 5%) 💩+ 7.4% ± 0.3%
peak_rss 1.49MB ± 0 1.49MB … 1.49MB 0 ( 0%) ⚡- 1.1% ± 0.0%
Benchmark 3 (2539 runs): gcc_a.out
measurement mean ± σ min … max outliers delta
wall_time 1.96ms ± 113us 1.76ms … 3.49ms 83 ( 3%) ⚡- 15.4% ± 0.3%
peak_rss 1.34MB ± 563 1.34MB … 1.36MB 3 ( 0%) ⚡- 10.9% ± 0.0%
Benchmark 4 (2489 runs): zcc_a.out
measurement mean ± σ min … max outliers delta
wall_time 2.00ms ± 99.6us 1.80ms … 2.76ms 79 ( 3%) ⚡- 13.7% ± 0.3%
peak_rss 1.38MB ± 464 1.38MB … 1.39MB 2 ( 0%) ⚡- 8.7% ± 0.0%

======== in order to benchmark, I also learn how to use crap, a fork of poop ========

Through reading, I also finally learn how Base64 encoding and decoding work (Not directly related to zig itself but happen to learn it while reading at zig tutorial in zig-book).

Learning is really nice. Now I continue to watch videos about how CPU works because of zig…and plan to attend a zig day in my holiday this year. We’ll see how it goes. XD