C++ VS Zig benchmarks

Current benchmark data was generated on Wed Feb 08 2023, full log can be found HERE

CONTRIBUTIONS are WELCOME!

[x86_64][2 cores] Intel(R) Xeon(R) Platinum 8171M CPU @ 2.60GHz (Model 85)

* -m in a file name stands for multi-threading or multi-processing

* -i in a file name stands for direct intrinsics usage. (Usage of simd intrinsics via libraries is not counted)

* -ffi in a file name stands for non-stdlib FFI usage

* (You may find time < time(user) + time(sys) for some non-parallelized programs, the overhead is from GC or JIT compiler, which are allowed to take advantage of multi-cores as that's more close to real-world scenarios.)

fannkuch-redux

Input: 11

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
cpp 1-im.cpp 794ms 8.7ms 3.9MB 1543ms 0ms clang++ 14.0.0
cpp 1-im.cpp 823ms 2.4ms 1.4MB 1570ms 0ms g++ 12.2.0
zig 2-m.zig 1401ms 16ms 1.1MB 2713ms 0ms zig 0.11.0-dev.1580+a5b34a61a
zig 3-i.zig 1699ms 3.5ms 1.0MB 1687ms 0ms zig 0.11.0-dev.1580+a5b34a61a
zig 2.zig 2854ms 1.2ms 1.0MB 2843ms 0ms zig 0.11.0-dev.1580+a5b34a61a
zig 1.zig 3856ms 30ms 1.0MB 3847ms 0ms zig 0.11.0-dev.1580+a5b34a61a

Input: 10

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
cpp 1-im.cpp 75ms 1.9ms 4.0MB 127ms 0ms clang++ 14.0.0
cpp 1-im.cpp 79ms 2.5ms 1.4MB 130ms 0ms g++ 12.2.0
zig 2-m.zig 134ms 1.0ms 1.1MB 233ms 0ms zig 0.11.0-dev.1580+a5b34a61a
zig 3-i.zig 145ms 0.7ms 1.0MB 130ms 0ms zig 0.11.0-dev.1580+a5b34a61a
zig 2.zig 242ms 0.2ms 1.0MB 230ms 0ms zig 0.11.0-dev.1580+a5b34a61a
zig 1.zig 323ms 0.7ms 1.0MB 310ms 0ms zig 0.11.0-dev.1580+a5b34a61a

helloworld

Input: QwQ

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
zig 1.zig 2.1ms 0.7ms 0.9MB 0ms 0ms zig 0.11.0-dev.1580+a5b34a61a
cpp 1.cpp 2.4ms 0.7ms 1.3MB 0ms 0ms g++ 12.2.0
cpp 1.cpp 2.4ms 0.7ms 1.4MB 0ms 0ms clang++ 14.0.0

nbody

Input: 5000000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
cpp 0-i.cpp 218ms 1.5ms 1.4MB 203ms 0ms g++ 12.2.0
cpp 0-i.cpp 253ms 4.3ms 1.4MB 243ms 0ms clang++ 14.0.0
zig 2.zig 308ms 5.8ms 1.1MB 293ms 0ms zig 0.11.0-dev.1580+a5b34a61a
cpp 1.cpp 413ms 9.0ms 1.4MB 400ms 0ms g++ 12.2.0
cpp 1.cpp 417ms 9.1ms 1.5MB 407ms 0ms clang++ 14.0.0
zig 1.zig 462ms 6.7ms 1.0MB 453ms 0ms zig 0.11.0-dev.1580+a5b34a61a

Input: 500000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
cpp 0-i.cpp 25ms 0.3ms 1.3MB 13ms 0ms g++ 12.2.0
cpp 0-i.cpp 28ms 0.2ms 1.4MB 20ms 0ms clang++ 14.0.0
zig 2.zig 35ms 0.6ms 1.0MB 27ms 0ms zig 0.11.0-dev.1580+a5b34a61a
cpp 1.cpp 45ms 0.3ms 1.4MB 40ms 0ms clang++ 14.0.0
cpp 1.cpp 46ms 1.9ms 1.3MB 40ms 0ms g++ 12.2.0
zig 1.zig 50ms 1.5ms 1.0MB 40ms 0ms zig 0.11.0-dev.1580+a5b34a61a

nsieve

Input: 12

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
zig 2.zig 439ms 0.8ms 6.0MB 423ms 0ms zig 0.11.0-dev.1580+a5b34a61a
cpp 1.cpp 769ms 8.0ms 7.4MB 750ms 0ms clang++ 14.0.0
cpp 1.cpp 769ms 17ms 7.7MB 753ms 0ms g++ 12.2.0
zig 1.zig 943ms 42ms 40.1MB 917ms 10ms zig 0.11.0-dev.1580+a5b34a61a

Input: 10

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
zig 2.zig 97ms 2.8ms 2.1MB 87ms 0ms zig 0.11.0-dev.1580+a5b34a61a
zig 1.zig 128ms 1.0ms 10.9MB 110ms 0ms zig 0.11.0-dev.1580+a5b34a61a
cpp 1.cpp 177ms 1.4ms 4.0MB 167ms 0ms g++ 12.2.0
cpp 1.cpp 185ms 4.4ms 3.9MB 173ms 0ms clang++ 14.0.0

spectral-norm

Input: 8000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
cpp 8-m.cpp 1061ms 4.5ms 3.7MB 2067ms 3ms clang++ 14.0.0
cpp 7-m.cpp 1065ms 5.3ms 3.3MB 2080ms 0ms clang++ 14.0.0
cpp 8-m.cpp 1071ms 5.9ms 1.3MB 2087ms 0ms g++ 12.2.0
cpp 7-m.cpp 1071ms 11ms 1.4MB 2073ms 0ms g++ 12.2.0
zig 2-m.zig 1088ms 3.9ms 1.2MB 2083ms 0ms zig 0.11.0-dev.1580+a5b34a61a
zig 2.zig 2072ms 6.8ms 1.0MB 2063ms 0ms zig 0.11.0-dev.1580+a5b34a61a
cpp 6-im.cpp 2187ms 29ms 1.3MB 4277ms 0ms g++ 12.2.0
cpp 6-im.cpp 2209ms 24ms 3.4MB 4327ms 3ms clang++ 14.0.0
zig 1.zig 4631ms 11ms 1.0MB 4617ms 0ms zig 0.11.0-dev.1580+a5b34a61a

Input: 4000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
cpp 7-m.cpp 271ms 2.1ms 1.3MB 510ms 0ms g++ 12.2.0
cpp 7-m.cpp 278ms 3.3ms 3.3MB 517ms 0ms clang++ 14.0.0
cpp 8-m.cpp 281ms 2.7ms 1.3MB 523ms 0ms g++ 12.2.0
cpp 8-m.cpp 283ms 8.5ms 3.5MB 527ms 0ms clang++ 14.0.0
zig 2-m.zig 284ms 2.0ms 1.2MB 510ms 0ms zig 0.11.0-dev.1580+a5b34a61a
zig 2.zig 525ms 10ms 1.0MB 513ms 0ms zig 0.11.0-dev.1580+a5b34a61a
cpp 6-im.cpp 546ms 13ms 1.3MB 1053ms 0ms g++ 12.2.0
cpp 6-im.cpp 560ms 0.6ms 3.3MB 1077ms 3ms clang++ 14.0.0
zig 1.zig 1156ms 3.2ms 1.0MB 1143ms 0ms zig 0.11.0-dev.1580+a5b34a61a

Input: 2000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
cpp 7-m.cpp 73ms 1.9ms 1.4MB 120ms 0ms g++ 12.2.0
cpp 8-m.cpp 77ms 0.2ms 3.3MB 130ms 0ms clang++ 14.0.0
cpp 8-m.cpp 78ms 1.5ms 1.3MB 130ms 0ms g++ 12.2.0
cpp 7-m.cpp 79ms 2.5ms 3.5MB 130ms 0ms clang++ 14.0.0
zig 2-m.zig 79ms 1.5ms 1.1MB 127ms 0ms zig 0.11.0-dev.1580+a5b34a61a
zig 2.zig 136ms 2.1ms 1.6MB 127ms 0ms zig 0.11.0-dev.1580+a5b34a61a
cpp 6-im.cpp 151ms 0.9ms 1.3MB 273ms 0ms g++ 12.2.0
cpp 6-im.cpp 152ms 0.4ms 3.7MB 273ms 0ms clang++ 14.0.0
zig 1.zig 294ms 0.5ms 1.0MB 280ms 0ms zig 0.11.0-dev.1580+a5b34a61a