Since my last post on interacting with C from Zig, I’ve been excited to play around more with the C ABI. This time I decided to try to compare the performance between algorithms implemented in C, Python, and Zig, as a fun exercise (and to boast about performance of the languages I love). So far I’ve only implemented Quick Sort, but am excited about the results.
On a set of 1000 random data points, over the course of 100 tests, it’s obvious that C and Zig outperform Python by a landslide. What isn’t so obvious is the result of Zig being faster than C. I know this method of testing isn’t absolute and bullet-proof, but its a fun exercise and I’m sure someone would like to play around with the code to see what results they can get.
original c++ version (with -O3 g++ option)
$ time ./fpaq0p c ~/CC/enwik8 zz
enwik8 (100000000 bytes) -> zz (61457810 bytes) in 10.98 s.
real 0m11,093s
user 0m10,831s
sys 0m0,172s
zig
$ time ./fpaq0p c ~/CC/enwik8 zz
enwik8 (100000000 bytes) -> zz (61457810 bytes) in 8890 msec
real 0m8,893s
user 0m8,753s
sys 0m0,136s
Idk if copy paste is a fair assessment of my code, considering I also test python. Moreover, i have a framework in place for testing more than just a single algorithm
to directly run the comparison if you want, also you might want to check your build dll import logic in python, because the directories were wrong, aka they were not in bin but in lib for me so I had to change it (as well as the extension but I was expecting that).