Zig VS Python benchmarks

Current benchmark data was generated on Wed May 25 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.)

binarytrees

Input: 18

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
python 1.py 1831ms 34ms 220.3MB 1667ms 147ms pypy 3.8.13
python 1.py timeout 0.0ms 0.0MB 0ms 0ms cpython 3.10.4
python 1.py timeout 0.0ms 0.0MB 0ms 0ms pyston 3.8.12
zig 1.zig timeout 0.0ms 0.0MB 0ms 0ms zig 0.10.0

Input: 15

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
python 1.py 140ms 3.4ms 78.6MB 107ms 20ms pypy 3.8.13
python 1.py 682ms 3.3ms 12.4MB 657ms 7ms pyston 3.8.12
python 1.py 1619ms 7.5ms 11.8MB 1603ms 0ms cpython 3.10.4
zig 1.zig 3757ms 23ms 8.0MB 3033ms 690ms zig 0.10.0

edigits

Input: 250001

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
python 1.py 753ms 3.4ms 82.9MB 707ms 27ms pypy 3.8.13
python 1.py 2245ms 159ms 9.3MB 2230ms 0ms cpython 3.10.4
python 1.py 2294ms 0.4ms 10.0MB 2283ms 0ms pyston 3.8.12
zig 1.zig timeout 0.0ms 0.0MB 0ms 0ms zig 0.10.0

Input: 100000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
python 1.py 199ms 12ms 76.2MB 163ms 17ms pypy 3.8.13
python 1.py 404ms 0.7ms 9.1MB 390ms 0ms pyston 3.8.12
python 1.py 419ms 0.5ms 8.5MB 407ms 0ms cpython 3.10.4
zig 1.zig 907ms 1.0ms 0.5MB 813ms 77ms zig 0.10.0

fannkuch-redux

Input: 11

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
zig 2-m.zig 1127ms 11ms 0.0MB 2177ms 0ms zig 0.10.0
zig 2.zig 2403ms 4.4ms 0.0MB 2387ms 3ms zig 0.10.0
zig 1.zig 3174ms 228ms 0.1MB 3163ms 0ms zig 0.10.0

Input: 10

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
zig 2-m.zig 99ms 0.3ms 0.0MB 170ms 0ms zig 0.10.0
zig 2.zig 197ms 14ms 0.0MB 183ms 0ms zig 0.10.0
zig 1.zig 269ms 8.6ms 0.1MB 257ms 0ms zig 0.10.0

fasta

Input: 2500000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
zig 1.zig 138ms 0.7ms 0.0MB 120ms 0ms zig 0.10.0
python 1.py 2907ms 44ms 89.2MB 2870ms 23ms pypy 3.8.13
python 5-m.py 3562ms 19ms 12.9MB 5000ms 1320ms pyston 3.8.12
python 1.py 4022ms 316ms 8.2MB 4003ms 3ms pyston 3.8.12
python 5-m.py 4407ms 159ms 12.1MB 6360ms 1213ms cpython 3.10.4
python 1.py timeout 0.0ms 0.0MB 0ms 0ms cpython 3.10.4
python 5-m.py timeout 0.0ms 0.0MB 0ms 0ms pypy 3.8.13

Input: 250000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
zig 1.zig 16ms 0.3ms 0.0MB 10ms 0ms zig 0.10.0
python 1.py 368ms 2.0ms 75.5MB 337ms 17ms pypy 3.8.13
python 5-m.py 432ms 6.5ms 12.9MB 537ms 173ms pyston 3.8.12
python 1.py 434ms 31ms 8.2MB 420ms 0ms pyston 3.8.12
python 5-m.py 545ms 3.4ms 12.1MB 683ms 197ms cpython 3.10.4
python 1.py 678ms 48ms 7.7MB 663ms 0ms cpython 3.10.4
python 5-m.py 910ms 3.9ms 78.8MB 1063ms 467ms pypy 3.8.13

helloworld

Input: QwQ

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
zig 1.zig 1.8ms 0.8ms 0.1MB 0ms 0ms zig 0.10.0
python 1.py 14ms 1.8ms 7.6MB 10ms 0ms pyston 3.8.12
python 1.py 16ms 2.8ms 7.3MB 10ms 0ms cpython 3.10.4
python 1.py 37ms 1.1ms 54.6MB 12ms 10ms pypy 3.8.13

lru

Input: 1000 1000000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
zig 1.zig 50ms 0.3ms 1.6MB 40ms 0ms zig 0.10.0
python 2.py 235ms 0.8ms 74.1MB 203ms 13ms pypy 3.8.13
python 1.py 280ms 0.3ms 75.4MB 250ms 17ms pypy 3.8.13
python 1.py 878ms 5.1ms 9.3MB 867ms 0ms pyston 3.8.12
python 2.py 1055ms 2.7ms 9.1MB 1040ms 0ms pyston 3.8.12
python 1.py 1743ms 15ms 8.4MB 1730ms 0ms cpython 3.10.4
python 2.py 2570ms 50ms 8.3MB 2557ms 0ms cpython 3.10.4

Input: 1000 3000000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
zig 1.zig 145ms 2.9ms 1.6MB 133ms 0ms zig 0.10.0
python 2.py 562ms 4.3ms 74.6MB 523ms 17ms pypy 3.8.13
python 1.py 614ms 2.1ms 76.1MB 583ms 17ms pypy 3.8.13
python 1.py 2586ms 14ms 9.3MB 2570ms 0ms pyston 3.8.12
python 2.py 3121ms 7.9ms 9.0MB 3107ms 0ms pyston 3.8.12
python 1.py timeout 0.0ms 0.0MB 0ms 0ms cpython 3.10.4
python 2.py timeout 0.0ms 0.0MB 0ms 0ms cpython 3.10.4

Input: 100 500000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
zig 1.zig 24ms 0.2ms 0.0MB 10ms 0ms zig 0.10.0
python 2.py 167ms 1.7ms 74.0MB 133ms 17ms pypy 3.8.13
python 1.py 184ms 0.5ms 74.3MB 143ms 17ms pypy 3.8.13
python 1.py 431ms 5.2ms 8.9MB 413ms 0ms pyston 3.8.12
python 2.py 487ms 2.4ms 8.5MB 477ms 0ms pyston 3.8.12
python 1.py 811ms 4.9ms 7.8MB 793ms 3ms cpython 3.10.4
python 2.py 1234ms 16ms 7.3MB 1217ms 0ms cpython 3.10.4

mandelbrot

Input: 5000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
zig 1.zig 349ms 20ms 3.1MB 337ms 0ms zig 0.10.0

Input: 1000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
zig 1.zig 17ms 1.0ms 0.0MB 10ms 0ms zig 0.10.0

merkletrees

Input: 17

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
python 1.py 2988ms 32ms 233.4MB 2767ms 203ms pypy 3.8.13
python 1.py timeout 0.0ms 0.0MB 0ms 0ms cpython 3.10.4
python 1.py timeout 0.0ms 0.0MB 0ms 0ms pyston 3.8.12
zig 1.zig timeout 0.0ms 0.0MB 0ms 0ms zig 0.10.0

Input: 15

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
python 1.py 443ms 13ms 151.0MB 363ms 60ms pypy 3.8.13
python 1.py timeout 0.0ms 0.0MB 0ms 0ms cpython 3.10.4
python 1.py timeout 0.0ms 0.0MB 0ms 0ms pyston 3.8.12
zig 1.zig timeout 0.0ms 0.0MB 0ms 0ms zig 0.10.0

nbody

Input: 5000000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
zig 2.zig 255ms 2.2ms 0.0MB 240ms 0ms zig 0.10.0
zig 1.zig 383ms 3.0ms 0.0MB 370ms 0ms zig 0.10.0
python 2.py 2271ms 62ms 74.5MB 2243ms 13ms pypy 3.8.13
python 1.py timeout 0.0ms 0.0MB 0ms 0ms cpython 3.10.4
python 2.py timeout 0.0ms 0.0MB 0ms 0ms cpython 3.10.4
python 1.py timeout 0.0ms 0.0MB 0ms 0ms pypy 3.8.13
python 1.py timeout 0.0ms 0.0MB 0ms 0ms pyston 3.8.12
python 2.py timeout 0.0ms 0.0MB 0ms 0ms pyston 3.8.12

Input: 500000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
zig 2.zig 29ms 2.9ms 0.0MB 20ms 0ms zig 0.10.0
zig 1.zig 41ms 1.0ms 0.0MB 30ms 0ms zig 0.10.0
python 2.py 294ms 5.0ms 74.1MB 253ms 27ms pypy 3.8.13
python 1.py 583ms 1.7ms 73.4MB 557ms 13ms pypy 3.8.13
python 1.py 1420ms 106ms 8.7MB 1407ms 0ms pyston 3.8.12
python 2.py 2057ms 12ms 8.5MB 2043ms 0ms pyston 3.8.12
python 1.py timeout 0.0ms 0.0MB 0ms 0ms cpython 3.10.4
python 2.py timeout 0.0ms 0.0MB 0ms 0ms cpython 3.10.4

nsieve

Input: 12

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
zig 2.zig 378ms 1.9ms 4.9MB 367ms 0ms zig 0.10.0
zig 1.zig 1136ms 42ms 39.1MB 1107ms 13ms zig 0.10.0
python 1.py timeout 0.0ms 0.0MB 0ms 0ms cpython 3.10.4
python 1.py timeout 0.0ms 0.0MB 0ms 0ms pypy 3.8.13
python 1.py timeout 0.0ms 0.0MB 0ms 0ms pyston 3.8.12

Input: 10

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
zig 2.zig 82ms 4.7ms 1.1MB 70ms 0ms zig 0.10.0
zig 1.zig 119ms 7.8ms 9.6MB 103ms 0ms zig 0.10.0
python 1.py 1357ms 20ms 209.6MB 1277ms 70ms pypy 3.8.13
python 1.py 2822ms 61ms 86.4MB 2770ms 37ms pyston 3.8.12
python 1.py timeout 0.0ms 0.0MB 0ms 0ms cpython 3.10.4

pidigits

Input: 8000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
python 4.py 2069ms 2.9ms 8.6MB 2037ms 20ms cpython 3.10.4
python 4.py 2237ms 2.1ms 9.4MB 2207ms 10ms pyston 3.8.12
python 4.py 2733ms 28ms 127.6MB 2640ms 73ms pypy 3.8.13
zig 1.zig timeout 0.0ms 0.0MB 0ms 0ms zig 0.10.0

Input: 4000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
python 4.py 502ms 4.7ms 8.4MB 480ms 0ms cpython 3.10.4
python 4.py 535ms 1.2ms 9.1MB 520ms 0ms pyston 3.8.12
python 4.py 702ms 4.2ms 79.7MB 670ms 20ms pypy 3.8.13
zig 1.zig 2845ms 10ms 0.4MB 1060ms 1770ms zig 0.10.0

spectral-norm

Input: 8000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
zig 2-m.zig 893ms 1.7ms 0.3MB 1660ms 0ms zig 0.10.0
zig 2.zig 1660ms 114ms 0.0MB 1650ms 0ms zig 0.10.0
zig 1.zig 3381ms 16ms 0.1MB 3370ms 0ms zig 0.10.0
python 8.py timeout 0.0ms 0.0MB 0ms 0ms cpython 3.10.4
python 8.py timeout 0.0ms 0.0MB 0ms 0ms pypy 3.8.13
python 8.py timeout 0.0ms 0.0MB 0ms 0ms pyston 3.8.12

Input: 4000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
zig 2-m.zig 230ms 1.2ms 0.2MB 410ms 0ms zig 0.10.0
zig 2.zig 420ms 28ms 0.0MB 413ms 0ms zig 0.10.0
zig 1.zig 850ms 1.6ms 0.1MB 840ms 0ms zig 0.10.0
python 8.py timeout 0.0ms 0.0MB 0ms 0ms cpython 3.10.4
python 8.py timeout 0.0ms 0.0MB 0ms 0ms pypy 3.8.13
python 8.py timeout 0.0ms 0.0MB 0ms 0ms pyston 3.8.12

Input: 2000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
zig 2-m.zig 65ms 2.2ms 0.2MB 93ms 0ms zig 0.10.0
zig 2.zig 100ms 0.4ms 0.0MB 90ms 0ms zig 0.10.0
zig 1.zig 226ms 22ms 0.1MB 213ms 0ms zig 0.10.0
python 8-m.py 4206ms 35ms 105.3MB 7317ms 397ms pypy 3.8.13
python 8.py timeout 0.0ms 0.0MB 0ms 0ms cpython 3.10.4
python 8.py timeout 0.0ms 0.0MB 0ms 0ms pyston 3.8.12