Nim VS C++ benchmarks

Current benchmark data was generated on Thu Sep 22 2022, full log can be found HERE

CONTRIBUTIONS are WELCOME!

[x86_64][2 cores] Intel(R) Xeon(R) Platinum 8370C CPU @ 2.80GHz (Model 106)

* -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 3403ms 74ms 34.2MB 3380ms 3ms nim/clang 1.6.6
nim 2.nim 3563ms 91ms 34.8MB 3533ms 10ms nim 1.6.6

Input: 15

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
nim 2.nim 320ms 2.8ms 5.7MB 307ms 0ms nim/clang 1.6.6
nim 2.nim 331ms 1.2ms 5.4MB 320ms 0ms nim 1.6.6

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 0.0MB 0ms 0ms nim 1.6.6
nim 1.nim timeout 0.0ms 0.0MB 0ms 0ms nim/clang 1.6.6

Input: 1000

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

edigits

Input: 250001

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

Input: 100000

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

fasta

Input: 2500000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
nim 2.nim 261ms 0.2ms 0.7MB 250ms 0ms nim 1.6.6
nim 2.nim 338ms 1.1ms 0.9MB 327ms 0ms nim/clang 1.6.6
nim 1.nim 789ms 1.3ms 0.7MB 683ms 93ms nim 1.6.6
nim 1.nim 808ms 1.1ms 0.9MB 697ms 93ms nim/clang 1.6.6

Input: 250000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
nim 2.nim 31ms 2.5ms 0.7MB 20ms 0ms nim 1.6.6
nim 2.nim 37ms 0.2ms 1.0MB 30ms 0ms nim/clang 1.6.6
nim 1.nim 84ms 0.3ms 1.0MB 67ms 3ms nim/clang 1.6.6
nim 1.nim 84ms 3.1ms 0.7MB 60ms 7ms nim 1.6.6

helloworld

Input: QwQ

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
nim 1.nim 1.3ms 0.1ms 0.9MB 0ms 0ms nim/clang 1.6.6
cpp 1.cpp 1.7ms 0.2ms 1.1MB 0ms 0ms clang++ 11.0.0
cpp 1.cpp 1.7ms 0.4ms 1.0MB 0ms 0ms g++ 12.2.0
nim 1.nim 2.2ms 0.8ms 0.7MB 0ms 0ms nim 1.6.6

http-server

Input: 3000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
nim 1.nim 740ms 4.9ms 94.6MB 317ms 387ms nim/clang 1.6.6
nim 1.nim 752ms 2.9ms 94.3MB 340ms 377ms nim 1.6.6

Input: 500

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
nim 1.nim 124ms 1.3ms 18.2MB 50ms 60ms nim/clang 1.6.6
nim 1.nim 129ms 1.5ms 17.7MB 60ms 53ms nim 1.6.6

lru

Input: 1000 1000000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
nim 2.nim 149ms 4.5ms 1.0MB 140ms 0ms nim/clang 1.6.6
nim 2.nim 154ms 0.7ms 0.7MB 140ms 0ms nim 1.6.6
nim 1.nim timeout 0.0ms 0.0MB 0ms 0ms nim 1.6.6
nim 1.nim timeout 0.0ms 0.0MB 0ms 0ms nim/clang 1.6.6

Input: 1000 3000000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
nim 2.nim 436ms 5.6ms 0.9MB 423ms 0ms nim/clang 1.6.6
nim 2.nim 455ms 0.8ms 0.7MB 443ms 0ms nim 1.6.6
nim 1.nim timeout 0.0ms 0.0MB 0ms 0ms nim 1.6.6
nim 1.nim timeout 0.0ms 0.0MB 0ms 0ms nim/clang 1.6.6

Input: 100 500000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
nim 2.nim 64ms 1.4ms 1.0MB 50ms 0ms nim/clang 1.6.6
nim 2.nim 67ms 1.0ms 0.7MB 60ms 0ms nim 1.6.6
nim 1.nim 416ms 6.8ms 1.0MB 403ms 0ms nim/clang 1.6.6
nim 1.nim 465ms 5.6ms 0.7MB 453ms 0ms nim 1.6.6

mandelbrot

Input: 5000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
nim 1.nim 575ms 0.6ms 4.8MB 563ms 0ms nim/clang 1.6.6
nim 1.nim 996ms 1.1ms 4.5MB 987ms 0ms nim 1.6.6

Input: 1000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
nim 1.nim 27ms 0.6ms 1.0MB 20ms 0ms nim/clang 1.6.6
nim 1.nim 44ms 0.8ms 0.7MB 37ms 0ms nim 1.6.6

merkletrees

Input: 17

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
nim 1.nim 1578ms 1.6ms 34.9MB 1560ms 3ms nim/clang 1.6.6
nim 1.nim 1661ms 1.3ms 34.8MB 1640ms 7ms nim 1.6.6

Input: 15

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
nim 1.nim 340ms 1.4ms 10.0MB 327ms 0ms nim/clang 1.6.6
nim 1.nim 357ms 0.5ms 9.2MB 343ms 0ms nim 1.6.6

nbody

Input: 5000000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
cpp 0-i.cpp 225ms 0.4ms 1.0MB 210ms 0ms g++ 12.2.0
cpp 0-i.cpp 258ms 0.9ms 1.1MB 243ms 0ms clang++ 11.0.0
cpp 1.cpp 339ms 0.5ms 1.0MB 330ms 0ms g++ 12.2.0
cpp 1.cpp 385ms 0.9ms 1.1MB 373ms 0ms clang++ 11.0.0
nim 2.nim 405ms 0.6ms 0.9MB 390ms 0ms nim/clang 1.6.6
nim 2.nim 428ms 0.4ms 1.0MB 420ms 0ms nim 1.6.6

Input: 500000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
cpp 0-i.cpp 25ms 0.3ms 1.0MB 17ms 0ms g++ 12.2.0
cpp 0-i.cpp 28ms 0.2ms 1.1MB 20ms 0ms clang++ 11.0.0
cpp 1.cpp 38ms 0.9ms 0.9MB 30ms 0ms g++ 12.2.0
cpp 1.cpp 42ms 1.4ms 1.1MB 30ms 0ms clang++ 11.0.0
nim 2.nim 44ms 0.7ms 1.0MB 30ms 0ms nim/clang 1.6.6
nim 2.nim 46ms 0.3ms 1.0MB 37ms 0ms nim 1.6.6

nsieve

Input: 12

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
cpp 1.cpp 415ms 0.6ms 7.4MB 403ms 0ms clang++ 11.0.0
nim 2.nim 588ms 1.5ms 6.8MB 577ms 0ms nim/clang 1.6.6
cpp 1.cpp 645ms 1.5ms 7.7MB 630ms 0ms g++ 12.2.0
nim 2.nim 671ms 3.4ms 6.1MB 663ms 0ms nim 1.6.6
nim 1.nim 744ms 0.6ms 40.2MB 727ms 0ms nim 1.6.6
nim 1.nim 824ms 35ms 41.0MB 803ms 3ms nim/clang 1.6.6

Input: 10

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
cpp 1.cpp 94ms 1.0ms 3.8MB 87ms 0ms clang++ 11.0.0
nim 1.nim 122ms 2.1ms 11.1MB 110ms 0ms nim 1.6.6
nim 1.nim 129ms 0.4ms 11.4MB 120ms 0ms nim/clang 1.6.6
nim 2.nim 140ms 1.0ms 3.3MB 130ms 0ms nim/clang 1.6.6
cpp 1.cpp 155ms 3.0ms 4.1MB 140ms 0ms g++ 12.2.0
nim 2.nim 159ms 1.2ms 2.9MB 150ms 0ms nim 1.6.6

pidigits

Input: 8000

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

Input: 4000

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

regex-redux

Input: 2500000_in

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
nim 1.nim 2569ms 2.8ms 168.2MB 2507ms 47ms nim/clang 1.6.6
nim 1.nim 2573ms 1.8ms 167.1MB 2530ms 27ms nim 1.6.6

Input: 250000_in

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
nim 1.nim 265ms 0.2ms 16.6MB 243ms 7ms nim 1.6.6
nim 1.nim 265ms 2.0ms 17.1MB 243ms 7ms nim/clang 1.6.6

spectral-norm

Input: 8000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
cpp 7-m.cpp 1060ms 3.2ms 3.2MB 2073ms 0ms clang++ 11.0.0
cpp 8-m.cpp 1062ms 3.4ms 3.1MB 2077ms 0ms clang++ 11.0.0
cpp 7-m.cpp 1063ms 1.9ms 0.9MB 2083ms 0ms g++ 12.2.0
cpp 8-m.cpp 1067ms 6.3ms 1.0MB 2083ms 0ms g++ 12.2.0
cpp 6-im.cpp 2241ms 18ms 0.9MB 4397ms 0ms g++ 12.2.0
cpp 6-im.cpp 2244ms 14ms 3.2MB 4407ms 0ms clang++ 11.0.0
nim 1.nim 4122ms 1.4ms 1.9MB 4110ms 0ms nim 1.6.6
nim 1.nim 4122ms 4.1ms 1.8MB 4110ms 0ms nim/clang 1.6.6

Input: 4000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
cpp 7-m.cpp 275ms 1.6ms 3.2MB 520ms 0ms clang++ 11.0.0
cpp 7-m.cpp 276ms 0.6ms 0.9MB 520ms 0ms g++ 12.2.0
cpp 8-m.cpp 276ms 3.4ms 3.2MB 520ms 0ms clang++ 11.0.0
cpp 8-m.cpp 277ms 0.5ms 0.9MB 523ms 0ms g++ 12.2.0
cpp 6-im.cpp 568ms 2.5ms 3.2MB 1100ms 0ms clang++ 11.0.0
cpp 6-im.cpp 570ms 2.4ms 0.9MB 1100ms 0ms g++ 12.2.0
nim 1.nim 1033ms 1.0ms 1.0MB 1020ms 0ms nim/clang 1.6.6
nim 1.nim 1033ms 0.4ms 1.0MB 1020ms 0ms nim 1.6.6

Input: 2000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
cpp 8-m.cpp 76ms 1.1ms 0.9MB 127ms 0ms g++ 12.2.0
cpp 8-m.cpp 77ms 2.8ms 3.2MB 130ms 0ms clang++ 11.0.0
cpp 7-m.cpp 77ms 1.9ms 3.2MB 127ms 0ms clang++ 11.0.0
cpp 7-m.cpp 79ms 2.3ms 1.0MB 133ms 0ms g++ 12.2.0
cpp 6-im.cpp 151ms 0.5ms 3.2MB 273ms 0ms clang++ 11.0.0
cpp 6-im.cpp 151ms 1.5ms 0.9MB 277ms 0ms g++ 12.2.0
nim 1.nim 260ms 0.2ms 1.0MB 250ms 0ms nim/clang 1.6.6
nim 1.nim 261ms 1.2ms 1.0MB 250ms 0ms nim 1.6.6