Nim VS C++ benchmarks

Current benchmark data was generated on Mon Feb 06 2023, 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.)

binarytrees

Input: 18

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
nim 2.nim 2133ms 3.3ms 33.6MB 2107ms 13ms nim 1.6.10
nim 2.nim 2138ms 5.8ms 35.0MB 2120ms 3ms nim/clang 1.6.10

Input: 15

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
nim 2.nim 201ms 0.2ms 5.7MB 190ms 0ms nim/clang 1.6.10
nim 2.nim 202ms 1.0ms 5.6MB 190ms 0ms nim 1.6.10

coro-prime-sieve

Input: 4000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
nim 1.nim timeout 0.0ms 429.3MB 3407ms 1243ms nim 1.6.10
nim 1.nim timeout 0.0ms 432.9MB 3397ms 1250ms nim/clang 1.6.10

Input: 1000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
nim 1.nim timeout 0.0ms 431.1MB 3390ms 1257ms nim 1.6.10
nim 1.nim timeout 0.0ms 433.4MB 3370ms 1273ms nim/clang 1.6.10

edigits

Input: 250001

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
nim 1.nim timeout 0.0ms 3.0MB 4983ms 0ms nim 1.6.10
nim 1.nim timeout 0.0ms 3.0MB 4987ms 0ms nim/clang 1.6.10

Input: 100000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
nim 1.nim timeout 0.0ms 2.3MB 4990ms 0ms nim 1.6.10
nim 1.nim timeout 0.0ms 2.2MB 4990ms 0ms nim/clang 1.6.10

fasta

Input: 2500000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
nim 2.nim 242ms 0.5ms 1.0MB 227ms 0ms nim 1.6.10
nim 2.nim 308ms 2.2ms 1.3MB 300ms 0ms nim/clang 1.6.10
nim 1.nim 690ms 3.1ms 1.2MB 593ms 80ms nim/clang 1.6.10
nim 1.nim 712ms 0.9ms 1.0MB 607ms 90ms nim 1.6.10

Input: 250000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
nim 2.nim 26ms 0.8ms 1.1MB 20ms 0ms nim 1.6.10
nim 2.nim 34ms 0.4ms 1.2MB 23ms 0ms nim/clang 1.6.10
nim 1.nim 72ms 1.4ms 1.2MB 53ms 3ms nim/clang 1.6.10
nim 1.nim 74ms 0.4ms 1.0MB 60ms 0ms nim 1.6.10

helloworld

Input: QwQ

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
nim 1.nim 1.4ms 0.5ms 1.0MB 0ms 0ms nim 1.6.10
nim 1.nim 1.7ms 0.5ms 1.3MB 0ms 0ms nim/clang 1.6.10
cpp 1.cpp 2.3ms 0.8ms 1.4MB 0ms 0ms clang++ 14.0.0
cpp 1.cpp 2.4ms 0.7ms 1.4MB 0ms 0ms g++ 12.2.0

http-server

Input: 3000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
nim 1.nim 848ms 0.3ms 93.8MB 397ms 420ms nim 1.6.10
nim 1.nim 881ms 2.7ms 94.5MB 433ms 417ms nim/clang 1.6.10

Input: 500

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
nim 1.nim 134ms 0.7ms 18.3MB 50ms 70ms nim 1.6.10
nim 1.nim 143ms 2.2ms 18.1MB 57ms 73ms nim/clang 1.6.10

lru

Input: 1000 1000000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
nim 2.nim 149ms 0.3ms 1.3MB 140ms 0ms nim/clang 1.6.10
nim 2.nim 152ms 0.1ms 1.0MB 140ms 0ms nim 1.6.10
nim 1.nim timeout 0.0ms 1.0MB 4990ms 0ms nim 1.6.10
nim 1.nim timeout 0.0ms 1.3MB 4983ms 0ms nim/clang 1.6.10

Input: 1000 3000000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
nim 2.nim 440ms 0.3ms 1.2MB 430ms 0ms nim/clang 1.6.10
nim 2.nim 451ms 0.0ms 1.0MB 440ms 0ms nim 1.6.10
nim 1.nim timeout 0.0ms 1.1MB 4987ms 0ms nim 1.6.10
nim 1.nim timeout 0.0ms 1.3MB 4987ms 0ms nim/clang 1.6.10

Input: 100 500000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
nim 2.nim 65ms 0.4ms 1.2MB 53ms 0ms nim/clang 1.6.10
nim 2.nim 66ms 0.7ms 1.0MB 60ms 0ms nim 1.6.10
nim 1.nim 388ms 6.2ms 1.3MB 377ms 0ms nim/clang 1.6.10
nim 1.nim 438ms 20ms 1.0MB 427ms 0ms nim 1.6.10

mandelbrot

Input: 5000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
nim 1.nim 587ms 5.9ms 4.8MB 573ms 0ms nim/clang 1.6.10
nim 1.nim 869ms 0.8ms 4.5MB 860ms 0ms nim 1.6.10

Input: 1000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
nim 1.nim 27ms 0.5ms 1.2MB 20ms 0ms nim/clang 1.6.10
nim 1.nim 39ms 1.5ms 1.1MB 30ms 0ms nim 1.6.10

merkletrees

Input: 17

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
nim 1.nim 1081ms 3.0ms 34.6MB 1060ms 3ms nim/clang 1.6.10
nim 1.nim 1089ms 2.4ms 34.6MB 1063ms 7ms nim 1.6.10

Input: 15

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
nim 1.nim 230ms 0.3ms 9.3MB 217ms 0ms nim 1.6.10
nim 1.nim 230ms 0.9ms 9.5MB 217ms 0ms nim/clang 1.6.10

nbody

Input: 5000000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
cpp 0-i.cpp 184ms 0.1ms 1.3MB 173ms 0ms g++ 12.2.0
cpp 0-i.cpp 211ms 0.5ms 1.4MB 200ms 0ms clang++ 14.0.0
cpp 1.cpp 352ms 5.7ms 1.4MB 337ms 0ms clang++ 14.0.0
cpp 1.cpp 358ms 0.6ms 1.3MB 350ms 0ms g++ 12.2.0
nim 2.nim 404ms 0.9ms 1.3MB 390ms 0ms nim 1.6.10
nim 2.nim 415ms 13ms 1.2MB 403ms 0ms nim/clang 1.6.10

Input: 500000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
cpp 0-i.cpp 21ms 0.9ms 1.3MB 10ms 0ms g++ 12.2.0
cpp 0-i.cpp 26ms 1.3ms 1.4MB 17ms 0ms clang++ 14.0.0
cpp 1.cpp 38ms 1.3ms 1.4MB 30ms 0ms clang++ 14.0.0
cpp 1.cpp 39ms 1.6ms 1.4MB 30ms 0ms g++ 12.2.0
nim 2.nim 43ms 0.7ms 1.3MB 30ms 0ms nim 1.6.10
nim 2.nim 44ms 0.9ms 1.3MB 30ms 0ms nim/clang 1.6.10

nsieve

Input: 12

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
cpp 1.cpp 664ms 9.6ms 7.5MB 650ms 0ms g++ 12.2.0
cpp 1.cpp 682ms 1.2ms 7.5MB 667ms 0ms clang++ 14.0.0
nim 2.nim 689ms 7.0ms 6.3MB 677ms 0ms nim/clang 1.6.10
nim 2.nim 838ms 3.1ms 6.0MB 827ms 0ms nim 1.6.10
nim 1.nim 1031ms 44ms 40.6MB 1010ms 10ms nim 1.6.10
nim 1.nim 1316ms 20ms 41.3MB 1290ms 10ms nim/clang 1.6.10

Input: 10

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
nim 1.nim 122ms 2.5ms 11.1MB 107ms 0ms nim 1.6.10
nim 1.nim 142ms 1.3ms 11.2MB 130ms 0ms nim/clang 1.6.10
cpp 1.cpp 150ms 0.5ms 4.0MB 140ms 0ms g++ 12.2.0
nim 2.nim 154ms 1.1ms 3.3MB 140ms 0ms nim/clang 1.6.10
cpp 1.cpp 155ms 0.5ms 3.9MB 143ms 0ms clang++ 14.0.0
nim 2.nim 198ms 0.5ms 3.1MB 183ms 0ms nim 1.6.10

pidigits

Input: 8000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
nim 1.nim timeout 0.0ms 5.8MB 4980ms 0ms nim 1.6.10
nim 1.nim timeout 0.0ms 5.8MB 4983ms 0ms nim/clang 1.6.10

Input: 4000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
nim 1.nim timeout 0.0ms 5.9MB 4987ms 0ms nim 1.6.10
nim 1.nim timeout 0.0ms 5.8MB 4983ms 3ms nim/clang 1.6.10

regex-redux

Input: 2500000_in

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
nim 1.nim 2436ms 0.3ms 167.9MB 2367ms 47ms nim/clang 1.6.10
nim 1.nim 2487ms 3.3ms 167.2MB 2417ms 50ms nim 1.6.10

Input: 250000_in

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
nim 1.nim 249ms 1.1ms 17.1MB 237ms 0ms nim/clang 1.6.10
nim 1.nim 255ms 1.2ms 16.8MB 237ms 3ms nim 1.6.10

spectral-norm

Input: 8000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
cpp 7-m.cpp 894ms 1.2ms 3.3MB 1743ms 0ms clang++ 14.0.0
cpp 7-m.cpp 901ms 3.0ms 1.3MB 1753ms 0ms g++ 12.2.0
cpp 8-m.cpp 903ms 15ms 3.3MB 1740ms 3ms clang++ 14.0.0
cpp 8-m.cpp 903ms 1.4ms 1.3MB 1760ms 0ms g++ 12.2.0
cpp 6-im.cpp 1847ms 1.3ms 1.4MB 3627ms 0ms g++ 12.2.0
cpp 6-im.cpp 1870ms 13ms 3.4MB 3650ms 0ms clang++ 14.0.0
nim 1.nim 3433ms 1.3ms 1.3MB 3420ms 0ms nim/clang 1.6.10
nim 1.nim 3434ms 1.2ms 1.3MB 3420ms 0ms nim 1.6.10

Input: 4000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
cpp 7-m.cpp 235ms 0.2ms 3.4MB 440ms 0ms clang++ 14.0.0
cpp 7-m.cpp 236ms 1.9ms 1.3MB 437ms 0ms g++ 12.2.0
cpp 8-m.cpp 237ms 1.3ms 1.3MB 440ms 0ms g++ 12.2.0
cpp 8-m.cpp 239ms 3.1ms 3.3MB 440ms 0ms clang++ 14.0.0
cpp 6-im.cpp 473ms 1.6ms 3.3MB 907ms 0ms clang++ 14.0.0
cpp 6-im.cpp 477ms 3.6ms 1.3MB 907ms 0ms g++ 12.2.0
nim 1.nim 861ms 0.6ms 1.3MB 847ms 0ms nim 1.6.10
nim 1.nim 862ms 1.6ms 1.3MB 850ms 0ms nim/clang 1.6.10

Input: 2000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
cpp 7-m.cpp 65ms 0.3ms 3.2MB 107ms 0ms clang++ 14.0.0
cpp 7-m.cpp 66ms 0.4ms 1.3MB 110ms 0ms g++ 12.2.0
cpp 8-m.cpp 66ms 2.4ms 1.3MB 107ms 0ms g++ 12.2.0
cpp 8-m.cpp 69ms 0.9ms 3.6MB 110ms 0ms clang++ 14.0.0
cpp 6-im.cpp 127ms 0.2ms 3.6MB 227ms 0ms clang++ 14.0.0
cpp 6-im.cpp 128ms 2.0ms 1.3MB 227ms 0ms g++ 12.2.0
nim 1.nim 217ms 0.3ms 1.3MB 207ms 0ms nim/clang 1.6.10
nim 1.nim 218ms 0.4ms 1.3MB 207ms 0ms nim 1.6.10