Zig VS Ruby benchmarks

Current benchmark data was generated on Sat Jan 28 2023, 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
zig 1.zig 2472ms 47ms 49.1MB 2443ms 13ms zig 0.11.0-dev.1479+97b1a9bb6
ruby 1.rb timeout 0.0ms 72.6MB 4943ms 40ms ruby 3.2.0
ruby 1.rb timeout 0.0ms 115.6MB 4917ms 60ms ruby/yjit 3.2.0
ruby 1.rb timeout 0.0ms 612.7MB 8020ms 290ms truffleruby 22.3.1

Input: 15

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
zig 1.zig 187ms 2.1ms 7.1MB 173ms 0ms zig 0.11.0-dev.1479+97b1a9bb6
ruby 1.rb 565ms 6.7ms 40.7MB 530ms 17ms ruby/yjit 3.2.0
ruby 1.rb 1011ms 5.8ms 40.3MB 973ms 20ms ruby 3.2.0
ruby 1-m.rb 1081ms 25ms 419.3MB 1780ms 140ms truffleruby 22.3.1

edigits

Input: 250001

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
zig 1.zig 3837ms 6.8ms 2.5MB 3807ms 13ms zig 0.11.0-dev.1479+97b1a9bb6

Input: 100000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
zig 1.zig 635ms 0.5ms 2.0MB 610ms 10ms zig 0.11.0-dev.1479+97b1a9bb6

fannkuch-redux

Input: 11

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
zig 2-m.zig 1309ms 14ms 1.1MB 2527ms 0ms zig 0.11.0-dev.1479+97b1a9bb6
zig 3-i.zig 1555ms 2.2ms 1.0MB 1550ms 0ms zig 0.11.0-dev.1479+97b1a9bb6
zig 2.zig 2527ms 0.9ms 1.0MB 2517ms 0ms zig 0.11.0-dev.1479+97b1a9bb6
zig 1.zig 3491ms 11ms 0.9MB 3473ms 0ms zig 0.11.0-dev.1479+97b1a9bb6

Input: 10

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
zig 2-m.zig 121ms 3.8ms 1.1MB 210ms 0ms zig 0.11.0-dev.1479+97b1a9bb6
zig 3-i.zig 131ms 0.2ms 1.0MB 120ms 0ms zig 0.11.0-dev.1479+97b1a9bb6
zig 2.zig 219ms 0.2ms 1.0MB 210ms 0ms zig 0.11.0-dev.1479+97b1a9bb6
zig 1.zig 290ms 3.7ms 1.0MB 277ms 0ms zig 0.11.0-dev.1479+97b1a9bb6

fasta

Input: 2500000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
zig 1.zig 157ms 3.1ms 1.0MB 147ms 0ms zig 0.11.0-dev.1479+97b1a9bb6
ruby 6.rb 2359ms 2.6ms 43.6MB 2327ms 17ms ruby/yjit 3.2.0
ruby 6-m.rb 2687ms 54ms 389.5MB 4817ms 267ms truffleruby 22.3.1
ruby 6.rb 4361ms 91ms 43.0MB 4323ms 20ms ruby 3.2.0

Input: 250000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
zig 1.zig 18ms 0.7ms 1.0MB 10ms 0ms zig 0.11.0-dev.1479+97b1a9bb6
ruby 6.rb 313ms 1.0ms 34.9MB 287ms 13ms ruby/yjit 3.2.0
ruby 6.rb 502ms 1.2ms 34.4MB 467ms 20ms ruby 3.2.0
ruby 6-m.rb 887ms 40ms 341.9MB 1497ms 120ms truffleruby 22.3.1

helloworld

Input: QwQ

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
zig 1.zig 1.7ms 0.7ms 1.0MB 0ms 0ms zig 0.11.0-dev.1479+97b1a9bb6
ruby 1.rb 45ms 2.4ms 154.4MB 18ms 30ms truffleruby 22.3.1
ruby 1.rb 72ms 1.0ms 32.2MB 50ms 10ms ruby 3.2.0
ruby 1.rb 77ms 0.9ms 32.3MB 50ms 12ms ruby/yjit 3.2.0

json-serde

Input: sample 5000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
zig 1.zig 124ms 2.7ms 14.4MB 107ms 0ms zig 0.11.0-dev.1479+97b1a9bb6
ruby 1.rb 440ms 2.6ms 52.9MB 400ms 23ms ruby 3.2.0
ruby 1.rb 461ms 9.3ms 54.5MB 410ms 30ms ruby/yjit 3.2.0
ruby 1.rb timeout 0.0ms 465.4MB 9110ms 200ms truffleruby 22.3.1

Input: canada 15

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
zig 1.zig 725ms 6.2ms 75.1MB 677ms 30ms zig 0.11.0-dev.1479+97b1a9bb6
ruby 1.rb 4007ms 6.6ms 174.0MB 3903ms 87ms ruby/yjit 3.2.0
ruby 1.rb 4060ms 98ms 173.9MB 3957ms 90ms ruby 3.2.0
ruby 1.rb timeout 0.0ms 432.6MB 9203ms 197ms truffleruby 22.3.1

knucleotide

Input: 2500000_in

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
zig 1.zig 1177ms 15ms 25.7MB 1147ms 13ms zig 0.11.0-dev.1479+97b1a9bb6

Input: 250000_in

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
zig 1.zig 130ms 0.1ms 7.5MB 117ms 3ms zig 0.11.0-dev.1479+97b1a9bb6

lru

Input: 1000 1000000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
zig 1.zig 45ms 1.7ms 2.8MB 37ms 0ms zig 0.11.0-dev.1479+97b1a9bb6
ruby 1.rb 448ms 2.7ms 33.0MB 420ms 13ms ruby/yjit 3.2.0
ruby 1.rb 602ms 5.0ms 32.3MB 580ms 3ms ruby 3.2.0
ruby 1-m.rb 832ms 33ms 335.1MB 1183ms 100ms truffleruby 22.3.1

Input: 1000 3000000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
zig 1.zig 128ms 0.5ms 2.7MB 120ms 0ms zig 0.11.0-dev.1479+97b1a9bb6
ruby 1.rb 1183ms 7.0ms 33.0MB 1157ms 10ms ruby/yjit 3.2.0
ruby 1.rb 1478ms 87ms 370.8MB 1977ms 150ms truffleruby 22.3.1
ruby 1.rb 1648ms 12ms 32.4MB 1620ms 10ms ruby 3.2.0

Input: 100 500000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
zig 1.zig 21ms 0.6ms 1.0MB 10ms 0ms zig 0.11.0-dev.1479+97b1a9bb6
ruby 1.rb 264ms 2.9ms 32.9MB 233ms 13ms ruby/yjit 3.2.0
ruby 1.rb 334ms 3.9ms 32.3MB 307ms 17ms ruby 3.2.0
ruby 1-m.rb 619ms 11ms 311.7MB 913ms 103ms truffleruby 22.3.1

mandelbrot

Input: 5000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
zig 1.zig 429ms 1.3ms 4.1MB 417ms 0ms zig 0.11.0-dev.1479+97b1a9bb6

Input: 1000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
zig 1.zig 21ms 1.1ms 1.0MB 10ms 0ms zig 0.11.0-dev.1479+97b1a9bb6

merkletrees

Input: 17

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
zig 1.zig 1254ms 52ms 41.1MB 1230ms 3ms zig 0.11.0-dev.1479+97b1a9bb6
ruby 1.rb timeout 0.0ms 96.4MB 4933ms 47ms ruby 3.2.0
ruby 1.rb timeout 0.0ms 97.0MB 4927ms 57ms ruby/yjit 3.2.0
ruby 1.rb timeout 0.0ms 562.9MB 9010ms 220ms truffleruby 22.3.1

Input: 15

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
zig 1.zig 229ms 7.2ms 11.0MB 210ms 0ms zig 0.11.0-dev.1479+97b1a9bb6
ruby 1-m.rb 3464ms 95ms 580.1MB 6290ms 240ms truffleruby 22.3.1
ruby 1.rb 4125ms 19ms 53.7MB 4087ms 23ms ruby/yjit 3.2.0
ruby 1.rb 4936ms 27ms 52.7MB 4890ms 23ms ruby 3.2.0

nbody

Input: 5000000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
zig 2.zig 303ms 0.0ms 1.0MB 290ms 0ms zig 0.11.0-dev.1479+97b1a9bb6
zig 1.zig 370ms 1.0ms 1.1MB 360ms 0ms zig 0.11.0-dev.1479+97b1a9bb6
ruby 2.rb 1036ms 17ms 305.8MB 1233ms 93ms truffleruby 22.3.1
ruby 2.rb timeout 0.0ms 32.1MB 4977ms 7ms ruby 3.2.0
ruby 2.rb timeout 0.0ms 33.0MB 4973ms 10ms ruby/yjit 3.2.0

Input: 500000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
zig 2.zig 34ms 1.3ms 1.0MB 20ms 0ms zig 0.11.0-dev.1479+97b1a9bb6
zig 1.zig 40ms 0.4ms 1.1MB 30ms 0ms zig 0.11.0-dev.1479+97b1a9bb6
ruby 2-m.rb 471ms 46ms 316.8MB 680ms 137ms truffleruby 22.3.1
ruby 2.rb 2176ms 4.7ms 33.0MB 2153ms 7ms ruby/yjit 3.2.0
ruby 2.rb 3381ms 35ms 32.3MB 3360ms 3ms ruby 3.2.0

nsieve

Input: 12

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
zig 2.zig 432ms 1.8ms 6.0MB 420ms 0ms zig 0.11.0-dev.1479+97b1a9bb6
zig 1.zig 1184ms 219ms 40.2MB 1150ms 13ms zig 0.11.0-dev.1479+97b1a9bb6
ruby 1.rb timeout 0.0ms 344.6MB 4840ms 133ms ruby 3.2.0
ruby 1.rb timeout 0.0ms 345.0MB 4827ms 150ms ruby/yjit 3.2.0
ruby 1.rb timeout 0.0ms 685.1MB 5010ms 183ms truffleruby 22.3.1

Input: 10

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
zig 2.zig 96ms 0.3ms 2.3MB 90ms 0ms zig 0.11.0-dev.1479+97b1a9bb6
zig 1.zig 144ms 9.1ms 11.0MB 130ms 0ms zig 0.11.0-dev.1479+97b1a9bb6
ruby 1.rb 3156ms 53ms 419.9MB 3677ms 137ms truffleruby 22.3.1
ruby 1.rb timeout 0.0ms 151.0MB 4920ms 53ms ruby 3.2.0
ruby 1.rb timeout 0.0ms 151.5MB 4923ms 57ms ruby/yjit 3.2.0

pidigits

Input: 8000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
zig 1.zig 2315ms 1.3ms 2.3MB 2283ms 13ms zig 0.11.0-dev.1479+97b1a9bb6
ruby 1.rb timeout 0.0ms 157.9MB 4937ms 47ms ruby 3.2.0
ruby 1.rb timeout 0.0ms 159.9MB 4923ms 53ms ruby/yjit 3.2.0
ruby 1.rb timeout 0.0ms 461.5MB 9333ms 257ms truffleruby 22.3.1

Input: 4000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
zig 1.zig 519ms 0.2ms 1.8MB 507ms 0ms zig 0.11.0-dev.1479+97b1a9bb6
ruby 1-m.rb 2020ms 26ms 435.4MB 3657ms 173ms truffleruby 22.3.1
ruby 1.rb 2424ms 8.0ms 158.0MB 2343ms 63ms ruby 3.2.0
ruby 1.rb 2426ms 8.8ms 159.8MB 2343ms 67ms ruby/yjit 3.2.0

spectral-norm

Input: 8000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
zig 2-m.zig 1077ms 4.0ms 1.2MB 2070ms 0ms zig 0.11.0-dev.1479+97b1a9bb6
zig 2.zig 2063ms 0.5ms 1.1MB 2050ms 0ms zig 0.11.0-dev.1479+97b1a9bb6
zig 1.zig 4583ms 1.2ms 1.1MB 4570ms 0ms zig 0.11.0-dev.1479+97b1a9bb6
ruby 4.rb timeout 0.0ms 32.1MB 4967ms 13ms ruby 3.2.0
ruby 4.rb timeout 0.0ms 32.8MB 4970ms 13ms ruby/yjit 3.2.0
ruby 4.rb timeout 0.0ms 566.4MB 5240ms 247ms truffleruby 22.3.1

Input: 4000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
zig 2-m.zig 281ms 0.8ms 1.2MB 507ms 3ms zig 0.11.0-dev.1479+97b1a9bb6
zig 2.zig 518ms 0.4ms 1.0MB 510ms 0ms zig 0.11.0-dev.1479+97b1a9bb6
zig 1.zig 1153ms 2.0ms 1.0MB 1140ms 0ms zig 0.11.0-dev.1479+97b1a9bb6
ruby 4.rb timeout 0.0ms 32.2MB 4973ms 10ms ruby 3.2.0
ruby 4.rb timeout 0.0ms 32.8MB 4973ms 13ms ruby/yjit 3.2.0
ruby 4.rb timeout 0.0ms 562.1MB 5453ms 223ms truffleruby 22.3.1

Input: 2000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
zig 2-m.zig 79ms 0.2ms 1.2MB 130ms 0ms zig 0.11.0-dev.1479+97b1a9bb6
zig 2.zig 132ms 0.2ms 1.0MB 120ms 0ms zig 0.11.0-dev.1479+97b1a9bb6
zig 1.zig 293ms 0.5ms 1.0MB 280ms 0ms zig 0.11.0-dev.1479+97b1a9bb6
ruby 4.rb 2585ms 15ms 476.7MB 3107ms 167ms truffleruby 22.3.1
ruby 4.rb timeout 0.0ms 32.4MB 4967ms 10ms ruby 3.2.0
ruby 4.rb timeout 0.0ms 32.7MB 4967ms 13ms ruby/yjit 3.2.0