C++ VS C benchmarks

Current benchmark data was generated on Mon Dec 30 2024, full log can be found HERE

CONTRIBUTIONS are WELCOME!

[x86_64][4 cores] AMD EPYC 7763 64-Core Processor (Model 1)

* -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 402ms 4.4ms 4.5MB 1547ms 0ms g++ 11.4.0
cpp 1-im.cpp 426ms 19ms 7.9MB 1603ms 7ms clang++ 14.0.0-1ubuntu1.1

Input: 10

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
cpp 1-im.cpp 42ms 0.7ms 8.0MB 130ms 0ms clang++ 14.0.0-1ubuntu1.1
cpp 1-im.cpp 45ms 2.8ms 4.5MB 147ms 0ms g++ 11.4.0

helloworld

Input: QwQ

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
cpp 1.cpp 1.0ms 0.1ms 1.4MB 0ms 0ms g++ 11.4.0
c 1.c 1.0ms 0.0ms 1.4MB 0ms 0ms zigcc 0.13.0
c 1.c 1.3ms 0.1ms 2.1MB 0ms 0ms gcc 14.2.0
c 1.c 1.4ms 0.2ms 2.1MB 0ms 0ms clang 14.0.0-1ubuntu1.1
cpp 1.cpp 1.5ms 0.1ms 2.1MB 0ms 0ms clang++ 14.0.0-1ubuntu1.1

nbody

Input: 5000000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
cpp 0-i.cpp 166ms 0.2ms 1.5MB 160ms 0ms g++ 11.4.0
cpp 0-i.cpp 170ms 0.3ms 2.3MB 160ms 0ms clang++ 14.0.0-1ubuntu1.1
c 8-i.c 246ms 1.1ms 1.5MB 233ms 0ms zigcc 0.13.0
c 5.c 298ms 0.5ms 1.5MB 290ms 0ms zigcc 0.13.0
c 8-i.c 300ms 0.7ms 2.1MB 290ms 0ms clang 14.0.0-1ubuntu1.1
c 2.c 309ms 1.2ms 2.3MB 300ms 0ms gcc 14.2.0
c 2.c 311ms 1.6ms 1.5MB 300ms 0ms zigcc 0.13.0
c 5.c 311ms 0.5ms 2.3MB 300ms 0ms gcc 14.2.0
cpp 1.cpp 313ms 1.5ms 2.3MB 303ms 0ms clang++ 14.0.0-1ubuntu1.1
c 5.c 314ms 1.7ms 2.1MB 310ms 0ms clang 14.0.0-1ubuntu1.1
cpp 1.cpp 315ms 1.9ms 1.8MB 303ms 0ms g++ 11.4.0
c 2.c 325ms 14ms 2.1MB 313ms 0ms clang 14.0.0-1ubuntu1.1
c 8-i.c 332ms 1.3ms 2.3MB 320ms 0ms gcc 14.2.0

Input: 500000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
cpp 0-i.cpp 18ms 0.1ms 1.5MB 10ms 0ms g++ 11.4.0
cpp 0-i.cpp 19ms 0.1ms 2.3MB 10ms 0ms clang++ 14.0.0-1ubuntu1.1
c 8-i.c 27ms 0.5ms 1.5MB 20ms 0ms zigcc 0.13.0
c 5.c 32ms 0.4ms 1.5MB 20ms 0ms zigcc 0.13.0
c 8-i.c 33ms 0.6ms 2.1MB 23ms 0ms clang 14.0.0-1ubuntu1.1
c 5.c 33ms 0.0ms 2.3MB 27ms 0ms gcc 14.2.0
c 2.c 33ms 0.4ms 2.3MB 23ms 0ms gcc 14.2.0
c 2.c 34ms 0.3ms 1.5MB 27ms 0ms zigcc 0.13.0
cpp 1.cpp 34ms 0.6ms 2.3MB 27ms 0ms clang++ 14.0.0-1ubuntu1.1
cpp 1.cpp 34ms 0.8ms 1.8MB 20ms 0ms g++ 11.4.0
c 5.c 34ms 0.5ms 2.1MB 23ms 0ms clang 14.0.0-1ubuntu1.1
c 8-i.c 35ms 0.1ms 2.3MB 27ms 0ms gcc 14.2.0
c 2.c 35ms 1.7ms 2.1MB 23ms 0ms clang 14.0.0-1ubuntu1.1

nsieve

Input: 12

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
c 1.c 266ms 8.2ms 40.9MB 250ms 0ms gcc 14.2.0
c 1.c 273ms 3.6ms 40.8MB 257ms 0ms clang 14.0.0-1ubuntu1.1
c 1.c 303ms 15ms 40.3MB 287ms 3ms zigcc 0.13.0
cpp 1.cpp 481ms 0.5ms 7.3MB 470ms 0ms g++ 11.4.0
cpp 1.cpp 529ms 2.1ms 7.8MB 517ms 0ms clang++ 14.0.0-1ubuntu1.1

Input: 10

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
c 1.c 50ms 1.3ms 11.5MB 33ms 0ms clang 14.0.0-1ubuntu1.1
c 1.c 53ms 5.0ms 11.6MB 40ms 0ms gcc 14.2.0
c 1.c 60ms 2.8ms 11.0MB 47ms 0ms zigcc 0.13.0
cpp 1.cpp 119ms 1.3ms 3.6MB 110ms 0ms g++ 11.4.0
cpp 1.cpp 130ms 0.7ms 4.1MB 120ms 0ms clang++ 14.0.0-1ubuntu1.1

spectral-norm

Input: 8000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
cpp 8-m.cpp 476ms 13ms 5.3MB 1823ms 3ms clang++ 14.0.0-1ubuntu1.1
cpp 8-m.cpp 484ms 4.4ms 4.2MB 1877ms 0ms g++ 11.4.0
cpp 6-im.cpp 917ms 1.1ms 4.2MB 3600ms 0ms g++ 11.4.0
cpp 6-im.cpp 922ms 11ms 5.4MB 3593ms 0ms clang++ 14.0.0-1ubuntu1.1
c 6-im.c 959ms 3.7ms 4.1MB 3763ms 0ms gcc 14.2.0
c 4-m.c 963ms 1.3ms 4.1MB 3777ms 0ms gcc 14.2.0
c 6-im.c 1014ms 27ms 7.2MB 3937ms 13ms clang 14.0.0-1ubuntu1.1
c 5-im.c 1092ms 4.2ms 4.1MB 4290ms 0ms gcc 14.2.0
c 4-m.c 1118ms 3.5ms 7.3MB 4377ms 3ms clang 14.0.0-1ubuntu1.1
c 5-im.c 1329ms 4.7ms 5.3MB 5207ms 3ms clang 14.0.0-1ubuntu1.1
c 3-m.c 1873ms 45ms 5.3MB 7227ms 20ms clang 14.0.0-1ubuntu1.1
c 3-m.c 1974ms 7.7ms 4.1MB 7773ms 0ms gcc 14.2.0

Input: 4000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
cpp 8-m.cpp 124ms 0.6ms 5.4MB 450ms 0ms clang++ 14.0.0-1ubuntu1.1
cpp 8-m.cpp 133ms 9.6ms 4.1MB 487ms 0ms g++ 11.4.0
cpp 6-im.cpp 239ms 0.9ms 5.4MB 900ms 0ms clang++ 14.0.0-1ubuntu1.1
cpp 6-im.cpp 239ms 0.4ms 4.1MB 907ms 0ms g++ 11.4.0
c 6-im.c 248ms 1.1ms 4.0MB 947ms 0ms gcc 14.2.0
c 4-m.c 254ms 1.5ms 4.0MB 967ms 0ms gcc 14.2.0
c 6-im.c 259ms 0.3ms 5.3MB 977ms 0ms clang 14.0.0-1ubuntu1.1
c 5-im.c 287ms 5.1ms 4.0MB 1090ms 0ms gcc 14.2.0
c 4-m.c 288ms 0.9ms 5.1MB 1087ms 3ms clang 14.0.0-1ubuntu1.1
c 5-im.c 340ms 1.6ms 7.3MB 1303ms 0ms clang 14.0.0-1ubuntu1.1
c 3-m.c 471ms 13ms 5.4MB 1797ms 3ms clang 14.0.0-1ubuntu1.1
c 3-m.c 511ms 13ms 4.0MB 1970ms 0ms gcc 14.2.0

Input: 2000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
cpp 8-m.cpp 38ms 1.2ms 7.3MB 107ms 0ms clang++ 14.0.0-1ubuntu1.1
cpp 8-m.cpp 39ms 0.3ms 4.0MB 120ms 0ms g++ 11.4.0
cpp 6-im.cpp 70ms 3.2ms 4.0MB 240ms 0ms g++ 11.4.0
cpp 6-im.cpp 71ms 2.8ms 7.2MB 230ms 0ms clang++ 14.0.0-1ubuntu1.1
c 6-im.c 72ms 3.3ms 4.0MB 247ms 0ms gcc 14.2.0
c 6-im.c 72ms 1.3ms 7.1MB 247ms 0ms clang 14.0.0-1ubuntu1.1
c 4-m.c 77ms 9.0ms 4.0MB 263ms 0ms gcc 14.2.0
c 4-m.c 80ms 0.5ms 5.1MB 273ms 0ms clang 14.0.0-1ubuntu1.1
c 5-im.c 81ms 2.6ms 4.0MB 287ms 0ms gcc 14.2.0
c 5-im.c 92ms 0.5ms 5.2MB 317ms 3ms clang 14.0.0-1ubuntu1.1
c 3-m.c 129ms 7.0ms 5.1MB 460ms 0ms clang 14.0.0-1ubuntu1.1
c 3-m.c 135ms 1.0ms 4.0MB 500ms 0ms gcc 14.2.0