Ruby VS Zig benchmarks

Current benchmark data was generated on Wed Feb 08 2023, full log can be found HERE

CONTRIBUTIONS are WELCOME!

[x86_64][2 cores] Intel(R) Xeon(R) Platinum 8171M 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
zig 1.zig 2850ms 12ms 49.1MB 2820ms 13ms zig 0.11.0-dev.1580+a5b34a61a
ruby 1.rb timeout 0.0ms 72.6MB 4940ms 40ms ruby 3.2.0
ruby 1.rb timeout 0.0ms 82.1MB 4923ms 57ms ruby/yjit 3.2.0
ruby 1.rb timeout 0.0ms 471.3MB 8477ms 293ms truffleruby 22.3.1

Input: 15

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
zig 1.zig 237ms 2.6ms 7.0MB 220ms 0ms zig 0.11.0-dev.1580+a5b34a61a
ruby 1.rb 718ms 9.3ms 40.7MB 673ms 30ms ruby/yjit 3.2.0
ruby 1.rb 1269ms 18ms 40.3MB 1233ms 20ms ruby 3.2.0
ruby 1-m.rb 1341ms 27ms 400.1MB 2230ms 170ms truffleruby 22.3.1

coro-prime-sieve

Input: 4000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
ruby 1.rb 4296ms 59ms 82.8MB 4203ms 77ms ruby/yjit 3.2.0
ruby 1.rb timeout 0.0ms 81.5MB 4900ms 73ms ruby 3.2.0
ruby 1.rb timeout 0.0ms 1103.9MB 4400ms 1323ms truffleruby 22.3.1

Input: 1000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
ruby 1.rb 292ms 1.0ms 44.9MB 247ms 33ms ruby/yjit 3.2.0
ruby 1.rb 341ms 17ms 44.5MB 290ms 33ms ruby 3.2.0
ruby 1.rb timeout 0.0ms 1096.9MB 4293ms 1420ms truffleruby 22.3.1

fasta

Input: 2500000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
zig 1.zig 165ms 2.4ms 1.0MB 153ms 0ms zig 0.11.0-dev.1580+a5b34a61a
ruby 6.rb 2828ms 11ms 43.6MB 2787ms 27ms ruby/yjit 3.2.0
ruby 6-m.rb 3219ms 20ms 392.0MB 5753ms 340ms truffleruby 22.3.1
ruby 6.rb timeout 0.0ms 42.9MB 4957ms 23ms ruby 3.2.0

Input: 250000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
zig 1.zig 22ms 1.6ms 1.0MB 10ms 0ms zig 0.11.0-dev.1580+a5b34a61a
ruby 6.rb 368ms 4.1ms 35.0MB 337ms 17ms ruby/yjit 3.2.0
ruby 6.rb 594ms 3.7ms 34.4MB 557ms 17ms ruby 3.2.0
ruby 6-m.rb 1035ms 11ms 324.2MB 1757ms 143ms truffleruby 22.3.1

helloworld

Input: QwQ

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
zig 1.zig 2.1ms 0.7ms 0.9MB 0ms 0ms zig 0.11.0-dev.1580+a5b34a61a
ruby 1.rb 54ms 1.8ms 153.4MB 30ms 28ms truffleruby 22.3.1
ruby 1.rb 87ms 1.1ms 32.1MB 52ms 18ms ruby 3.2.0
ruby 1.rb 91ms 4.1ms 32.3MB 64ms 14ms 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 144ms 5.5ms 14.4MB 123ms 7ms zig 0.11.0-dev.1580+a5b34a61a
ruby 1.rb 536ms 9.1ms 52.0MB 493ms 27ms ruby/yjit 3.2.0
ruby 1.rb 539ms 2.7ms 54.3MB 493ms 27ms ruby 3.2.0
ruby 1.rb timeout 0.0ms 429.6MB 9103ms 237ms truffleruby 22.3.1

Input: canada 15

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
zig 1.zig 866ms 46ms 75.0MB 810ms 40ms zig 0.11.0-dev.1580+a5b34a61a
ruby 1.rb 4869ms 23ms 174.3MB 4730ms 123ms ruby/yjit 3.2.0
ruby 1.rb 4894ms 50ms 175.2MB 4767ms 110ms ruby 3.2.0
ruby 1.rb timeout 0.0ms 404.1MB 9173ms 250ms truffleruby 22.3.1

lru

Input: 1000 1000000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
zig 1.zig 59ms 1.7ms 2.8MB 50ms 0ms zig 0.11.0-dev.1580+a5b34a61a
ruby 1.rb 547ms 7.6ms 33.0MB 513ms 20ms ruby/yjit 3.2.0
ruby 1.rb 783ms 2.8ms 32.4MB 753ms 13ms ruby 3.2.0
ruby 1-m.rb 991ms 25ms 326.0MB 1430ms 137ms truffleruby 22.3.1

Input: 1000 3000000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
zig 1.zig 164ms 1.5ms 2.9MB 150ms 0ms zig 0.11.0-dev.1580+a5b34a61a
ruby 1.rb 1475ms 1.9ms 33.0MB 1447ms 13ms ruby/yjit 3.2.0
ruby 1.rb 1943ms 72ms 333.2MB 2463ms 183ms truffleruby 22.3.1
ruby 1.rb 2117ms 13ms 32.4MB 2083ms 17ms ruby 3.2.0

Input: 100 500000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
zig 1.zig 33ms 8.3ms 1.3MB 23ms 0ms zig 0.11.0-dev.1580+a5b34a61a
ruby 1.rb 319ms 2.1ms 32.8MB 290ms 13ms ruby/yjit 3.2.0
ruby 1.rb 426ms 2.6ms 32.3MB 397ms 10ms ruby 3.2.0
ruby 1-m.rb 739ms 68ms 311.2MB 1117ms 130ms truffleruby 22.3.1

merkletrees

Input: 17

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
zig 1.zig 1335ms 3.4ms 41.1MB 1300ms 13ms zig 0.11.0-dev.1580+a5b34a61a
ruby 1.rb timeout 0.0ms 96.5MB 4910ms 73ms ruby 3.2.0
ruby 1.rb timeout 0.0ms 97.0MB 4913ms 70ms ruby/yjit 3.2.0
ruby 1.rb timeout 0.0ms 511.3MB 9013ms 283ms truffleruby 22.3.1

Input: 15

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
zig 1.zig 269ms 1.4ms 11.0MB 253ms 0ms zig 0.11.0-dev.1580+a5b34a61a
ruby 1-m.rb 4229ms 57ms 589.3MB 7687ms 320ms truffleruby 22.3.1
ruby 1.rb 4784ms 22ms 53.7MB 4710ms 57ms ruby/yjit 3.2.0
ruby 1.rb timeout 0.0ms 52.8MB 4943ms 37ms ruby 3.2.0

nbody

Input: 5000000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
zig 2.zig 308ms 5.8ms 1.1MB 293ms 0ms zig 0.11.0-dev.1580+a5b34a61a
zig 1.zig 462ms 6.7ms 1.0MB 453ms 0ms zig 0.11.0-dev.1580+a5b34a61a
ruby 2.rb 1435ms 12ms 298.5MB 1713ms 100ms truffleruby 22.3.1
ruby 2.rb timeout 0.0ms 32.2MB 4970ms 13ms ruby 3.2.0
ruby 2.rb timeout 0.0ms 33.0MB 4963ms 13ms ruby/yjit 3.2.0

Input: 500000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
zig 2.zig 35ms 0.6ms 1.0MB 27ms 0ms zig 0.11.0-dev.1580+a5b34a61a
zig 1.zig 50ms 1.5ms 1.0MB 40ms 0ms zig 0.11.0-dev.1580+a5b34a61a
ruby 2-m.rb 513ms 25ms 309.9MB 770ms 127ms truffleruby 22.3.1
ruby 2.rb 2528ms 32ms 33.1MB 2487ms 23ms ruby/yjit 3.2.0
ruby 2.rb 4072ms 73ms 32.2MB 4043ms 13ms ruby 3.2.0

nsieve

Input: 12

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
zig 2.zig 439ms 0.8ms 6.0MB 423ms 0ms zig 0.11.0-dev.1580+a5b34a61a
zig 1.zig 943ms 42ms 40.1MB 917ms 10ms zig 0.11.0-dev.1580+a5b34a61a
ruby 1.rb timeout 0.0ms 344.6MB 4780ms 197ms ruby 3.2.0
ruby 1.rb timeout 0.0ms 344.9MB 4787ms 190ms ruby/yjit 3.2.0
ruby 1.rb timeout 0.0ms 682.1MB 5030ms 217ms truffleruby 22.3.1

Input: 10

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
zig 2.zig 97ms 2.8ms 2.1MB 87ms 0ms zig 0.11.0-dev.1580+a5b34a61a
zig 1.zig 128ms 1.0ms 10.9MB 110ms 0ms zig 0.11.0-dev.1580+a5b34a61a
ruby 1.rb 3780ms 6.1ms 431.4MB 4390ms 167ms truffleruby 22.3.1
ruby 1.rb timeout 0.0ms 151.0MB 4900ms 77ms ruby 3.2.0
ruby 1.rb timeout 0.0ms 151.5MB 4893ms 90ms 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 2406ms 1.7ms 2.3MB 2373ms 13ms zig 0.11.0-dev.1580+a5b34a61a
ruby 1.rb timeout 0.0ms 159.1MB 4913ms 67ms ruby 3.2.0
ruby 1.rb timeout 0.0ms 159.8MB 4903ms 73ms ruby/yjit 3.2.0
ruby 1.rb timeout 0.0ms 430.8MB 9380ms 223ms truffleruby 22.3.1

Input: 4000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
zig 1.zig 558ms 10ms 1.8MB 547ms 0ms zig 0.11.0-dev.1580+a5b34a61a
ruby 1-m.rb 2551ms 7.6ms 419.5MB 4673ms 190ms truffleruby 22.3.1
ruby 1.rb 3739ms 3.7ms 158.8MB 3630ms 87ms ruby/yjit 3.2.0
ruby 1.rb 3746ms 14ms 158.0MB 3647ms 80ms ruby 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 1088ms 3.9ms 1.2MB 2083ms 0ms zig 0.11.0-dev.1580+a5b34a61a
zig 2.zig 2072ms 6.8ms 1.0MB 2063ms 0ms zig 0.11.0-dev.1580+a5b34a61a
zig 1.zig 4631ms 11ms 1.0MB 4617ms 0ms zig 0.11.0-dev.1580+a5b34a61a
ruby 4.rb timeout 0.0ms 32.2MB 4967ms 10ms ruby 3.2.0
ruby 4.rb timeout 0.0ms 32.9MB 4973ms 13ms ruby/yjit 3.2.0
ruby 4.rb timeout 0.0ms 404.5MB 5227ms 213ms truffleruby 22.3.1

Input: 4000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
zig 2-m.zig 284ms 2.0ms 1.2MB 510ms 0ms zig 0.11.0-dev.1580+a5b34a61a
zig 2.zig 525ms 10ms 1.0MB 513ms 0ms zig 0.11.0-dev.1580+a5b34a61a
zig 1.zig 1156ms 3.2ms 1.0MB 1143ms 0ms zig 0.11.0-dev.1580+a5b34a61a
ruby 4.rb timeout 0.0ms 32.2MB 4970ms 17ms ruby 3.2.0
ruby 4.rb timeout 0.0ms 32.8MB 4957ms 20ms ruby/yjit 3.2.0
ruby 4.rb timeout 0.0ms 460.5MB 5583ms 183ms 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 1.5ms 1.1MB 127ms 0ms zig 0.11.0-dev.1580+a5b34a61a
zig 2.zig 136ms 2.1ms 1.6MB 127ms 0ms zig 0.11.0-dev.1580+a5b34a61a
zig 1.zig 294ms 0.5ms 1.0MB 280ms 0ms zig 0.11.0-dev.1580+a5b34a61a
ruby 4.rb 3275ms 18ms 360.5MB 3963ms 167ms truffleruby 22.3.1
ruby 4.rb timeout 0.0ms 32.0MB 4960ms 23ms ruby 3.2.0
ruby 4.rb timeout 0.0ms 32.9MB 4967ms 10ms ruby/yjit 3.2.0