Zig ReleaseSafe faster than ReleaseFast
I noticed some strange behavior in the Zig benchmark for Levenshtein.
When compiling with the ReleaseSafe flag, performance is way better than when using ReleaseFast.
(Zig v0.13.0)
Since the ReleaseFast Flag removes safety checks, among other things, this is very unusual.
The only thing I can think of is the longer startup time due to the larger binary size. In my opinion, that shouldn't make that much of a difference.
Zig code is also generally very slow compared to C, Cpp and Rust.
compile 'zig' 'zig build-exe -O ReleaseSafe -femit-bin=zig/code zig/code.zig'
compile 'zig' 'zig build-exe -O ReleaseFast -femit-bin=zig/code zig/code.zig'
Also setting option target to x86_64-native can counteract this sometimes.
compile 'zig' 'zig build-exe -O ReleaseFast -target x86_64-native -femit-bin=zig/code zig/code.zig'
compile 'zig' 'zig build-exe -O ReleaseSafe -target x86_64-native -femit-bin=zig/code zig/code.zig'
that test mostly measures startup time anyways, so it's not that surprising
I've just started a version of this project, where we measure in-process, without startup times included, over here https://github.com/PEZ/languages-fun
Please feel invited to add Zig there. Super WIP, but I hope the README explains what needs to be done.
that test mostly measures startup time anyways, so it's not that surprising
It was the Zig benchmark for Levenshtein. Shouldn't take much longer than C/Cpp/Rust (or any other language without VM) for startup. Most of the runtime should be taken up by the algorithm itself.
I think I have now figured out what causes this behavior. This is probably the same LLVM-Issue #91370 for my znver3 CPU (AMD Ryzen 9 5950X 16-Core Processor) as the one already described in my comment for Issue #351 (read that for more details).
Since the current Zig code in master branch is broken, my benchmarks include the changes from PR #355.
Equivalent to Rust's -Ctarget-cpu=native here are the differences with Zig's -mcpu znver2.
zig build-exe -O ReleaseFast -static -femit-bin=zig/code zig/code.zig && ../run.sh
zig build-exe -O ReleaseFast -static -mcpu znver2 -femit-bin=zig/code zig/code.zig && ../run.sh
Additionally, it should be mentioned that in addition to LLVM's CPU feature detection, Zig also contains its own. (see also Comment for Zig #19793)
# Zig CPU detection
zig detect-cpu
# LLVM CPU detection
zig detect-cpu --llvm
Compare differences in feature detection. (ideally there are none)
diff <(zig detect-cpu) <(zig detect-cpu --llvm)