C VS C++ benchmarks

Current benchmark data was generated on Fri Sep 30 2022, full log can be found HERE

CONTRIBUTIONS are WELCOME!

[x86_64][2 cores] Intel(R) Xeon(R) Platinum 8272CL 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.)

helloworld

Input: QwQ

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
c 1.c 1.7ms 0.4ms 1.0MB 0ms 0ms gcc 12.2.0
cpp 1.cpp 1.9ms 0.7ms 1.0MB 0ms 0ms g++ 12.2.0
c 1.c 2.5ms 1.3ms 1.1MB 0ms 0ms clang 11.0.0
cpp 1.cpp 2.6ms 0.6ms 1.1MB 0ms 0ms clang++ 11.0.0
c 1.c 2.8ms 1.6ms 0.6MB 0ms 0ms zigcc 0.10.0-dev.4198+5e0d8a435

knucleotide

Input: 2500000_in

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
c 1-m.c 235ms 4.0ms 23.5MB 390ms 3ms gcc 12.2.0
c 1-m.c 492ms 39ms 20.5MB 790ms 30ms clang 11.0.0

Input: 250000_in

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
c 1.c 34ms 0.7ms 12.5MB 40ms 0ms gcc 12.2.0
c 1-m.c 59ms 3.9ms 9.7MB 93ms 0ms clang 11.0.0

nbody

Input: 5000000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
cpp 0-i.cpp 183ms 0.4ms 1.0MB 170ms 0ms g++ 12.2.0
cpp 0-i.cpp 212ms 0.1ms 1.1MB 200ms 0ms clang++ 11.0.0
c 8-i.c 267ms 0.4ms 0.6MB 257ms 0ms zigcc 0.10.0-dev.4198+5e0d8a435
c 8-i.c 317ms 1.8ms 1.1MB 310ms 0ms clang 11.0.0
c 8-i.c 330ms 0.2ms 1.0MB 320ms 0ms gcc 12.2.0
c 5.c 336ms 1.2ms 1.0MB 320ms 0ms gcc 12.2.0
c 5.c 354ms 0.5ms 0.6MB 340ms 0ms zigcc 0.10.0-dev.4198+5e0d8a435
cpp 1.cpp 357ms 0.5ms 0.9MB 350ms 0ms g++ 12.2.0
c 5.c 357ms 0.5ms 1.1MB 350ms 0ms clang 11.0.0
c 2.c 363ms 0.4ms 0.6MB 350ms 0ms zigcc 0.10.0-dev.4198+5e0d8a435
cpp 1.cpp 399ms 14ms 1.1MB 387ms 0ms clang++ 11.0.0
c 2.c 469ms 5.1ms 1.1MB 450ms 0ms clang 11.0.0
c 2.c 474ms 1.7ms 0.9MB 460ms 0ms gcc 12.2.0

Input: 500000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
cpp 0-i.cpp 21ms 0.4ms 0.9MB 10ms 0ms g++ 12.2.0
cpp 0-i.cpp 23ms 0.3ms 1.1MB 13ms 0ms clang++ 11.0.0
c 8-i.c 29ms 0.4ms 0.5MB 20ms 0ms zigcc 0.10.0-dev.4198+5e0d8a435
c 8-i.c 35ms 0.3ms 1.0MB 20ms 0ms clang 11.0.0
c 5.c 36ms 0.4ms 0.9MB 27ms 0ms gcc 12.2.0
c 8-i.c 38ms 3.2ms 1.0MB 27ms 0ms gcc 12.2.0
c 5.c 38ms 0.4ms 0.6MB 30ms 0ms zigcc 0.10.0-dev.4198+5e0d8a435
cpp 1.cpp 38ms 0.4ms 1.0MB 30ms 0ms g++ 12.2.0
c 5.c 38ms 0.5ms 1.1MB 30ms 0ms clang 11.0.0
c 2.c 39ms 0.4ms 0.6MB 30ms 0ms zigcc 0.10.0-dev.4198+5e0d8a435
cpp 1.cpp 44ms 1.0ms 1.1MB 30ms 0ms clang++ 11.0.0
c 2.c 50ms 0.1ms 0.9MB 40ms 0ms gcc 12.2.0
c 2.c 50ms 1.0ms 1.1MB 40ms 0ms clang 11.0.0

nsieve

Input: 12

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
cpp 1.cpp 377ms 1.7ms 7.4MB 363ms 0ms clang++ 11.0.0
cpp 1.cpp 637ms 2.1ms 7.7MB 623ms 0ms g++ 12.2.0
c 1.c 1061ms 28ms 40.9MB 1027ms 13ms clang 11.0.0
c 1.c 1079ms 44ms 41.1MB 1047ms 17ms gcc 12.2.0
c 1.c 1215ms 63ms 40.2MB 1170ms 30ms zigcc 0.10.0-dev.4198+5e0d8a435

Input: 10

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
cpp 1.cpp 81ms 0.3ms 3.8MB 70ms 0ms clang++ 11.0.0
c 1.c 115ms 2.7ms 10.7MB 97ms 0ms zigcc 0.10.0-dev.4198+5e0d8a435
c 1.c 116ms 0.5ms 11.5MB 103ms 0ms clang 11.0.0
c 1.c 116ms 4.9ms 11.7MB 97ms 0ms gcc 12.2.0
cpp 1.cpp 147ms 0.7ms 4.0MB 133ms 0ms g++ 12.2.0

spectral-norm

Input: 8000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
cpp 7-m.cpp 892ms 4.0ms 3.2MB 1737ms 0ms clang++ 11.0.0
cpp 7-m.cpp 894ms 6.6ms 1.0MB 1737ms 0ms g++ 12.2.0
cpp 8-m.cpp 897ms 1.9ms 1.0MB 1743ms 0ms g++ 12.2.0
cpp 8-m.cpp 900ms 4.4ms 3.2MB 1750ms 0ms clang++ 11.0.0
c 4-m.c 1262ms 6.4ms 0.9MB 2467ms 0ms gcc 12.2.0
c 6-im.c 1439ms 1.2ms 1.0MB 2813ms 0ms gcc 12.2.0
c 6-im.c 1443ms 17ms 3.2MB 2813ms 3ms clang 11.0.0
c 4-m.c 1543ms 17ms 3.1MB 3013ms 3ms clang 11.0.0
c 5-im.c 1587ms 17ms 1.0MB 3090ms 0ms gcc 12.2.0
c 5-im.c 1741ms 0.8ms 3.0MB 3407ms 0ms clang 11.0.0
cpp 6-im.cpp 1837ms 2.9ms 0.9MB 3600ms 0ms g++ 12.2.0
cpp 6-im.cpp 1838ms 23ms 3.2MB 3597ms 3ms clang++ 11.0.0
c 3-m.c 1878ms 5.5ms 1.0MB 3680ms 0ms gcc 12.2.0
c 3-m.c 1889ms 16ms 3.1MB 3700ms 0ms clang 11.0.0

Input: 4000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
cpp 7-m.cpp 232ms 0.3ms 3.2MB 430ms 0ms clang++ 11.0.0
cpp 8-m.cpp 235ms 1.7ms 0.9MB 440ms 0ms g++ 12.2.0
cpp 7-m.cpp 236ms 4.7ms 1.0MB 433ms 0ms g++ 12.2.0
cpp 8-m.cpp 237ms 1.6ms 3.2MB 440ms 0ms clang++ 11.0.0
c 4-m.c 331ms 3.8ms 1.0MB 623ms 0ms gcc 12.2.0
c 6-im.c 371ms 0.5ms 3.1MB 710ms 0ms clang 11.0.0
c 6-im.c 374ms 5.9ms 1.0MB 700ms 0ms gcc 12.2.0
c 4-m.c 396ms 2.7ms 3.1MB 753ms 0ms clang 11.0.0
c 5-im.c 412ms 1.2ms 0.9MB 783ms 0ms gcc 12.2.0
c 5-im.c 444ms 1.2ms 3.2MB 847ms 3ms clang 11.0.0
cpp 6-im.cpp 467ms 2.4ms 3.1MB 893ms 0ms clang++ 11.0.0
cpp 6-im.cpp 470ms 2.8ms 1.0MB 903ms 0ms g++ 12.2.0
c 3-m.c 481ms 0.5ms 1.0MB 920ms 0ms gcc 12.2.0
c 3-m.c 482ms 2.1ms 3.2MB 920ms 0ms clang 11.0.0

Input: 2000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
cpp 8-m.cpp 65ms 1.2ms 0.9MB 110ms 0ms g++ 12.2.0
cpp 7-m.cpp 67ms 2.0ms 3.2MB 110ms 0ms clang++ 11.0.0
cpp 7-m.cpp 67ms 3.0ms 1.0MB 110ms 0ms g++ 12.2.0
cpp 8-m.cpp 68ms 2.0ms 3.2MB 107ms 0ms clang++ 11.0.0
c 4-m.c 91ms 1.8ms 0.9MB 160ms 0ms gcc 12.2.0
c 6-im.c 100ms 0.4ms 1.0MB 170ms 0ms gcc 12.2.0
c 6-im.c 100ms 0.1ms 3.3MB 173ms 0ms clang 11.0.0
c 4-m.c 109ms 1.1ms 3.1MB 190ms 0ms clang 11.0.0
c 5-im.c 114ms 0.4ms 1.0MB 200ms 0ms gcc 12.2.0
c 5-im.c 123ms 3.1ms 3.2MB 217ms 0ms clang 11.0.0
cpp 6-im.cpp 126ms 1.5ms 3.1MB 227ms 0ms clang++ 11.0.0
cpp 6-im.cpp 126ms 0.2ms 1.0MB 223ms 0ms g++ 12.2.0
c 3-m.c 129ms 1.3ms 3.1MB 230ms 0ms clang 11.0.0
c 3-m.c 131ms 2.6ms 1.0MB 230ms 0ms gcc 12.2.0