Nim VS Python 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.)

binarytrees

Input: 18

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
nim 2.nim 766ms 2.6ms 34.8MB 750ms 3ms nim 2.2.0
nim 2.nim 957ms 3.4ms 34.2MB 943ms 3ms nim/clang 2.2.0
python 1.py 1166ms 9.2ms 95.7MB 1100ms 50ms pypy 3.10.14
python 1.py timeout 0.0ms 40.9MB 4967ms 17ms cpython 3.13.1
python 1.py timeout 0.0ms 40.5MB 4760ms 223ms pyston 3.8.12

Input: 15

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
nim 2.nim 76ms 3.6ms 5.5MB 67ms 0ms nim 2.2.0
nim 2.nim 92ms 0.6ms 5.8MB 80ms 0ms nim/clang 2.2.0
python 1.py 96ms 2.2ms 67.9MB 63ms 20ms pypy 3.10.14
python 1.py 474ms 5.7ms 11.9MB 450ms 7ms pyston 3.8.12
python 1.py 709ms 7.3ms 12.6MB 697ms 0ms cpython 3.13.1

coro-prime-sieve

Input: 4000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
python 1.py 1177ms 7.4ms 102.5MB 1120ms 40ms pypy 3.10.14
nim 1.nim timeout 0.0ms 546.2MB 2487ms 2057ms nim 2.2.0
nim 1.nim timeout 0.0ms 552.6MB 2530ms 2013ms nim/clang 2.2.0
python 1.py timeout 0.0ms 21.3MB 4973ms 7ms cpython 3.13.1
python 1.py timeout 0.0ms 17.3MB 4980ms 3ms pyston 3.8.12

Input: 1000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
python 1.py 218ms 5.6ms 84.5MB 167ms 37ms pypy 3.10.14
python 1.py 587ms 33ms 20.5MB 567ms 3ms cpython 3.13.1
python 1.py 656ms 19ms 16.8MB 630ms 3ms pyston 3.8.12
nim 1.nim 4364ms 34ms 518.7MB 2180ms 1760ms nim/clang 2.2.0
nim 1.nim 4534ms 2.9ms 518.2MB 2227ms 1877ms nim 2.2.0

fasta

Input: 2500000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
nim 2.nim 184ms 1.6ms 1.5MB 170ms 0ms nim 2.2.0
nim 2.nim 239ms 0.6ms 1.8MB 227ms 0ms nim/clang 2.2.0
nim 1.nim 572ms 3.7ms 1.8MB 443ms 117ms nim/clang 2.2.0
nim 1.nim 597ms 1.9ms 1.5MB 467ms 117ms nim 2.2.0
python 1.py 1896ms 11ms 88.3MB 1847ms 33ms pypy 3.10.14
python 5-m.py 2474ms 26ms 12.5MB 3627ms 973ms pyston 3.8.12
python 5-m.py 2831ms 4.6ms 64.9MB 4040ms 807ms pypy 3.10.14
python 1.py 2999ms 24ms 8.1MB 2983ms 0ms pyston 3.8.12
python 5-m.py 3390ms 14ms 13.9MB 4597ms 887ms cpython 3.13.1
python 1.py 4550ms 39ms 8.6MB 4537ms 0ms cpython 3.13.1

Input: 250000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
nim 2.nim 21ms 0.3ms 1.5MB 10ms 0ms nim 2.2.0
nim 2.nim 25ms 0.1ms 1.8MB 13ms 0ms nim/clang 2.2.0
nim 1.nim 62ms 3.4ms 1.8MB 40ms 10ms nim/clang 2.2.0
nim 1.nim 62ms 0.6ms 1.5MB 40ms 7ms nim 2.2.0
python 1.py 252ms 5.8ms 63.5MB 227ms 17ms pypy 3.10.14
python 1.py 310ms 1.9ms 8.1MB 297ms 0ms pyston 3.8.12
python 5-m.py 311ms 4.2ms 12.5MB 410ms 137ms pyston 3.8.12
python 5-m.py 397ms 2.8ms 13.8MB 483ms 127ms cpython 3.13.1
python 1.py 494ms 18ms 8.6MB 480ms 0ms cpython 3.13.1
python 5-m.py 539ms 0.3ms 65.0MB 810ms 283ms pypy 3.10.14

helloworld

Input: QwQ

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
nim 1.nim 1.0ms 0.1ms 1.6MB 0ms 0ms nim 2.2.0
nim 1.nim 1.1ms 0.1ms 1.8MB 0ms 0ms nim/clang 2.2.0
python 1.py 11ms 1.0ms 7.6MB 0ms 0ms pyston 3.8.12
python 1.py 13ms 1.3ms 8.6MB 10ms 0ms cpython 3.13.1
python 1.py 28ms 0.7ms 51.0MB 10ms 8ms pypy 3.10.14

http-server

Input: 3000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
nim 1.nim 971ms 14ms 99.4MB 257ms 690ms nim/clang 2.2.0
nim 1.nim 988ms 12ms 99.3MB 257ms 700ms nim 2.2.0
python 1.py 2122ms 18ms 36.4MB 1073ms 1570ms pyston 3.8.12
python 1.py 2389ms 181ms 33.4MB 1510ms 1657ms cpython 3.13.1
python 1.py 4757ms 102ms 107.1MB 2770ms 1207ms pypy 3.10.14

Input: 500

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
nim 1.nim 159ms 2.7ms 18.1MB 33ms 110ms nim 2.2.0
nim 1.nim 164ms 4.9ms 18.4MB 43ms 103ms nim/clang 2.2.0
python 1.py 1147ms 80ms 28.7MB 303ms 280ms cpython 3.13.1
python 1.py 1183ms 95ms 31.0MB 233ms 270ms pyston 3.8.12
python 1.py 1563ms 329ms 89.5MB 690ms 227ms pypy 3.10.14

lru

Input: 1000 1000000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
nim 2.nim 110ms 0.9ms 1.9MB 100ms 0ms nim/clang 2.2.0
nim 2.nim 114ms 1.4ms 1.4MB 103ms 0ms nim 2.2.0
python 2.py 147ms 1.4ms 57.9MB 123ms 10ms pypy 3.10.14
python 1.py 178ms 5.0ms 59.5MB 153ms 10ms pypy 3.10.14
python 1.py 726ms 18ms 8.9MB 713ms 0ms pyston 3.8.12
python 2.py 833ms 14ms 8.5MB 827ms 0ms pyston 3.8.12
python 1.py 1123ms 16ms 9.4MB 1113ms 0ms cpython 3.13.1
python 2.py 1312ms 12ms 9.0MB 1300ms 0ms cpython 3.13.1
nim 1.nim timeout 0.0ms 1.3MB 4987ms 0ms nim 2.2.0
nim 1.nim timeout 0.0ms 1.5MB 4990ms 0ms nim/clang 2.2.0

Input: 1000 3000000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
nim 2.nim 321ms 3.0ms 1.6MB 310ms 0ms nim/clang 2.2.0
nim 2.nim 338ms 2.7ms 1.5MB 327ms 0ms nim 2.2.0
python 2.py 345ms 7.5ms 58.9MB 317ms 13ms pypy 3.10.14
python 1.py 374ms 2.4ms 60.4MB 347ms 10ms pypy 3.10.14
python 1.py 2112ms 9.0ms 8.9MB 2097ms 0ms pyston 3.8.12
python 2.py 2470ms 27ms 8.5MB 2453ms 0ms pyston 3.8.12
python 1.py 3297ms 22ms 9.4MB 3280ms 0ms cpython 3.13.1
python 2.py 3873ms 38ms 9.0MB 3857ms 3ms cpython 3.13.1
nim 1.nim timeout 0.0ms 1.3MB 4990ms 0ms nim 2.2.0
nim 1.nim timeout 0.0ms 1.5MB 4990ms 0ms nim/clang 2.2.0

Input: 100 500000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
nim 2.nim 49ms 2.0ms 1.5MB 40ms 0ms nim/clang 2.2.0
nim 2.nim 51ms 1.7ms 1.3MB 43ms 0ms nim 2.2.0
python 2.py 104ms 2.3ms 57.8MB 77ms 10ms pypy 3.10.14
python 1.py 119ms 0.8ms 58.5MB 90ms 13ms pypy 3.10.14
python 1.py 342ms 1.9ms 8.5MB 330ms 0ms pyston 3.8.12
python 2.py 384ms 1.2ms 8.1MB 370ms 0ms pyston 3.8.12
nim 1.nim 494ms 5.1ms 1.5MB 480ms 0ms nim/clang 2.2.0
nim 1.nim 497ms 11ms 1.3MB 483ms 0ms nim 2.2.0
python 1.py 527ms 8.2ms 9.0MB 510ms 0ms cpython 3.13.1
python 2.py 638ms 14ms 8.6MB 623ms 0ms cpython 3.13.1

mandelbrot

Input: 5000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
nim 1.nim 385ms 1.1ms 4.8MB 370ms 0ms nim/clang 2.2.0
nim 1.nim 576ms 3.5ms 4.5MB 567ms 0ms nim 2.2.0

Input: 1000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
nim 1.nim 18ms 0.5ms 1.9MB 10ms 0ms nim/clang 2.2.0
nim 1.nim 27ms 1.4ms 1.6MB 17ms 0ms nim 2.2.0

merkletrees

Input: 17

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
nim 1.nim 550ms 4.2ms 34.9MB 527ms 7ms nim 2.2.0
nim 1.nim 601ms 10.0ms 35.2MB 583ms 7ms nim/clang 2.2.0
python 1.py 2228ms 12ms 210.0MB 2107ms 107ms pypy 3.10.14
python 1.py timeout 0.0ms 93.9MB 4957ms 30ms cpython 3.13.1
python 1.py timeout 0.0ms 130.4MB 4930ms 50ms pyston 3.8.12

Input: 15

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
nim 1.nim 119ms 0.7ms 9.6MB 107ms 0ms nim 2.2.0
nim 1.nim 129ms 2.9ms 9.9MB 120ms 0ms nim/clang 2.2.0
python 1.py 381ms 4.2ms 103.6MB 330ms 37ms pypy 3.10.14
python 1.py 2924ms 26ms 36.9MB 2890ms 20ms cpython 3.13.1
python 1.py timeout 0.0ms 48.8MB 4940ms 40ms pyston 3.8.12

nbody

Input: 5000000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
nim 2.nim 319ms 1.8ms 1.8MB 310ms 0ms nim 2.2.0
nim 2.nim 342ms 2.3ms 2.0MB 327ms 0ms nim/clang 2.2.0
python 2.py 1353ms 12ms 59.9MB 1337ms 3ms pypy 3.10.14
python 1.py 2633ms 14ms 56.6MB 2607ms 13ms pypy 3.10.14
python 1.py timeout 0.0ms 8.6MB 4990ms 0ms cpython 3.13.1
python 2.py timeout 0.0ms 8.8MB 4987ms 0ms cpython 3.13.1
python 1.py timeout 0.0ms 8.3MB 4983ms 0ms pyston 3.8.12
python 2.py timeout 0.0ms 8.1MB 4983ms 0ms pyston 3.8.12

Input: 500000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
nim 2.nim 35ms 0.9ms 1.8MB 23ms 0ms nim 2.2.0
nim 2.nim 36ms 0.3ms 2.0MB 30ms 0ms nim/clang 2.2.0
python 2.py 177ms 3.9ms 57.6MB 153ms 10ms pypy 3.10.14
python 1.py 305ms 2.4ms 56.6MB 283ms 7ms pypy 3.10.14
python 1.py 946ms 19ms 8.3MB 937ms 0ms pyston 3.8.12
python 2.py 1298ms 20ms 8.1MB 1280ms 0ms pyston 3.8.12
python 1.py 2997ms 82ms 8.8MB 2987ms 0ms cpython 3.13.1
python 2.py 3190ms 235ms 8.8MB 3177ms 0ms cpython 3.13.1

nsieve

Input: 12

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
nim 1.nim 262ms 5.5ms 41.5MB 250ms 0ms nim 2.2.0
nim 1.nim 317ms 11ms 41.8MB 300ms 0ms nim/clang 2.2.0
python 1.py 2535ms 9.1ms 369.1MB 2463ms 57ms pypy 3.10.14
python 2.py 2952ms 18ms 633.0MB 2773ms 163ms pyston 3.8.12
python 1.py 4904ms 18ms 320.4MB 4843ms 43ms pyston 3.8.12
python 1.py timeout 0.0ms 321.1MB 4960ms 27ms cpython 3.13.1
python 2.py timeout 0.0ms 633.5MB 4817ms 170ms cpython 3.13.1
python 2.py timeout 0.0ms 959.4MB 4733ms 253ms pypy 3.10.14

Input: 10

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
nim 1.nim 53ms 0.6ms 11.5MB 43ms 0ms nim 2.2.0
nim 1.nim 63ms 3.5ms 11.8MB 53ms 0ms nim/clang 2.2.0
python 1.py 526ms 8.6ms 134.6MB 483ms 27ms pypy 3.10.14
python 2.py 710ms 4.5ms 164.2MB 667ms 27ms pyston 3.8.12
python 1.py 1093ms 7.3ms 86.0MB 1067ms 10ms pyston 3.8.12
python 2.py 1416ms 3.8ms 165.0MB 1367ms 30ms cpython 3.13.1
python 2.py 1536ms 11ms 289.6MB 1443ms 77ms pypy 3.10.14
python 1.py 2657ms 8.6ms 86.8MB 2630ms 10ms cpython 3.13.1

regex-redux

Input: 2500000_in

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
nim 1.nim 1623ms 5.2ms 151.9MB 1587ms 20ms nim/clang 2.2.0
nim 1.nim 1645ms 3.9ms 151.5MB 1607ms 23ms nim 2.2.0
python 1.py 2230ms 6.1ms 244.1MB 2163ms 50ms pypy 3.10.14
python 1.py 4730ms 18ms 226.2MB 4550ms 160ms pyston 3.8.12
python 1.py timeout 0.0ms 111.6MB 4950ms 37ms cpython 3.13.1

Input: 250000_in

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
nim 1.nim 172ms 2.5ms 17.5MB 157ms 0ms nim/clang 2.2.0
nim 1.nim 173ms 1.9ms 17.2MB 160ms 0ms nim 2.2.0
python 1.py 330ms 1.4ms 84.8MB 287ms 30ms pypy 3.10.14
python 1.py 492ms 4.4ms 30.4MB 460ms 17ms pyston 3.8.12
python 1.py 628ms 2.8ms 31.0MB 590ms 27ms cpython 3.13.1

spectral-norm

Input: 8000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
nim 1.nim 3575ms 2.8ms 1.6MB 3563ms 0ms nim/clang 2.2.0
nim 1.nim 3593ms 7.9ms 1.4MB 3583ms 0ms nim 2.2.0
python 8.py timeout 0.0ms 16.7MB 57ms 7ms cpython 3.13.1
python 8.py timeout 0.0ms 100.1MB 863ms 163ms pypy 3.10.14
python 8.py timeout 0.0ms 18.1MB 73ms 20ms pyston 3.8.12

Input: 4000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
nim 1.nim 895ms 0.8ms 1.5MB 883ms 0ms nim/clang 2.2.0
nim 1.nim 902ms 3.4ms 1.3MB 893ms 0ms nim 2.2.0
python 8.py timeout 0.0ms 16.5MB 103ms 17ms cpython 3.13.1
python 8.py timeout 0.0ms 100.0MB 1510ms 497ms pypy 3.10.14
python 8.py timeout 0.0ms 17.8MB 127ms 43ms pyston 3.8.12

Input: 2000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
nim 1.nim 226ms 0.3ms 1.6MB 220ms 0ms nim 2.2.0
nim 1.nim 226ms 0.5ms 1.5MB 213ms 0ms nim/clang 2.2.0
python 8-m.py 1991ms 11ms 95.1MB 6310ms 350ms pypy 3.10.14
python 8.py timeout 0.0ms 16.1MB 257ms 50ms cpython 3.13.1
python 8.py timeout 0.0ms 17.2MB 433ms 100ms pyston 3.8.12