Ruby VS Rust benchmarks

Current benchmark data was generated on Mon Feb 06 2023, 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
rust 4.rs 1746ms 19ms 33.8MB 1717ms 13ms rustc 1.67.0
rust 5.rs 1946ms 27ms 33.7MB 1917ms 13ms rustc 1.67.0
rust 3.rs 2082ms 16ms 49.9MB 2047ms 20ms rustc 1.67.0
ruby 1.rb timeout 0.0ms 72.6MB 4943ms 40ms ruby 3.2.0
ruby 1.rb timeout 0.0ms 100.2MB 4937ms 43ms ruby/yjit 3.2.0
ruby 1.rb timeout 0.0ms 499.1MB 8423ms 310ms truffleruby 22.3.1

Input: 15

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
rust 4.rs 153ms 0.2ms 5.7MB 140ms 0ms rustc 1.67.0
rust 5.rs 168ms 0.6ms 5.8MB 160ms 0ms rustc 1.67.0
rust 3.rs 177ms 2.0ms 7.8MB 167ms 0ms rustc 1.67.0
ruby 1.rb 600ms 3.1ms 40.7MB 567ms 17ms ruby/yjit 3.2.0
ruby 1.rb 1122ms 5.1ms 40.2MB 1097ms 13ms ruby 3.2.0
ruby 1-m.rb 1195ms 48ms 434.8MB 1953ms 170ms truffleruby 22.3.1

coro-prime-sieve

Input: 4000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
rust 3-m.rs 1016ms 80ms 6.2MB 1933ms 33ms rustc 1.67.0
rust 5-m.rs 1190ms 249ms 4.3MB 2270ms 40ms rustc 1.67.0
rust 3.rs 2025ms 60ms 6.2MB 1983ms 27ms rustc 1.67.0
rust 4.rs 3020ms 14ms 4.4MB 3007ms 0ms rustc 1.67.0
rust 1-m.rs 3466ms 17ms 5.0MB 6697ms 97ms rustc 1.67.0
ruby 1.rb 4122ms 30ms 82.7MB 4040ms 63ms ruby/yjit 3.2.0
ruby 1.rb timeout 0.0ms 77.8MB 4917ms 63ms ruby 3.2.0
ruby 1.rb timeout 0.0ms 1107.6MB 4193ms 1413ms truffleruby 22.3.1

Input: 1000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
rust 3-m.rs 98ms 17ms 2.8MB 140ms 3ms rustc 1.67.0
rust 3.rs 118ms 1.2ms 3.2MB 100ms 0ms rustc 1.67.0
rust 5-m.rs 119ms 15ms 2.6MB 197ms 10ms rustc 1.67.0
rust 4.rs 198ms 2.2ms 2.4MB 183ms 0ms rustc 1.67.0
rust 1-m.rs 232ms 0.0ms 2.8MB 413ms 17ms rustc 1.67.0
ruby 1.rb 266ms 2.2ms 45.1MB 227ms 23ms ruby/yjit 3.2.0
ruby 1.rb 304ms 3.5ms 44.3MB 257ms 30ms ruby 3.2.0
ruby 1.rb timeout 0.0ms 1091.8MB 4383ms 1290ms truffleruby 22.3.1

fasta

Input: 2500000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
rust 5c-m.rs 177ms 2.2ms 1.7MB 310ms 0ms rustc 1.69.0-nightly
rust 5-m.rs 196ms 3.3ms 1.7MB 347ms 0ms rustc 1.67.0
rust 1c.rs 213ms 0.5ms 1.1MB 200ms 0ms rustc 1.69.0-nightly
rust 1.rs 272ms 8.0ms 1.0MB 260ms 0ms rustc 1.67.0
ruby 6.rb 2378ms 0.7ms 43.6MB 2337ms 27ms ruby/yjit 3.2.0
ruby 6-m.rb 2793ms 58ms 383.3MB 4990ms 307ms truffleruby 22.3.1
ruby 6.rb 4253ms 47ms 43.1MB 4210ms 27ms ruby 3.2.0

Input: 250000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
rust 1c.rs 25ms 0.5ms 1.0MB 17ms 0ms rustc 1.69.0-nightly
rust 5c-m.rs 29ms 1.4ms 1.7MB 27ms 0ms rustc 1.69.0-nightly
rust 1.rs 30ms 0.5ms 1.1MB 20ms 0ms rustc 1.67.0
rust 5-m.rs 31ms 0.8ms 1.8MB 40ms 0ms rustc 1.67.0
ruby 6.rb 312ms 1.0ms 35.0MB 277ms 17ms ruby/yjit 3.2.0
ruby 6.rb 502ms 6.0ms 34.4MB 473ms 13ms ruby 3.2.0
ruby 6-m.rb 905ms 19ms 321.2MB 1523ms 133ms truffleruby 22.3.1

helloworld

Input: QwQ

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
rust 1.rs 1.8ms 0.6ms 1.7MB 0ms 0ms rustc 1.69.0-nightly
rust 1.rs 2.4ms 0.7ms 1.0MB 0ms 0ms rustc 1.67.0
ruby 1.rb 52ms 3.6ms 165.0MB 28ms 30ms truffleruby 22.3.1
ruby 1.rb 77ms 1.6ms 32.3MB 52ms 10ms ruby/yjit 3.2.0
ruby 1.rb 81ms 1.0ms 32.2MB 54ms 16ms ruby 3.2.0

json-serde

Input: sample 5000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
rust 2.rs 80ms 0.2ms 38.1MB 57ms 7ms rustc 1.67.0
rust 3.rs 83ms 1.8ms 36.3MB 53ms 13ms rustc 1.67.0
rust 1.rs 146ms 8.2ms 75.5MB 87ms 43ms rustc 1.67.0
ruby 1.rb 462ms 4.3ms 54.5MB 423ms 20ms ruby/yjit 3.2.0
ruby 1.rb 472ms 2.2ms 51.8MB 430ms 23ms ruby 3.2.0
ruby 1.rb timeout 0.0ms 460.8MB 9140ms 237ms truffleruby 22.3.1

Input: canada 15

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
rust 2.rs 505ms 1.3ms 257.9MB 367ms 117ms rustc 1.67.0
rust 3.rs 519ms 1.0ms 258.7MB 390ms 113ms rustc 1.67.0
rust 1.rs 926ms 1.8ms 605.6MB 653ms 257ms rustc 1.67.0
ruby 1.rb 4072ms 8.8ms 175.6MB 3980ms 70ms ruby/yjit 3.2.0
ruby 1.rb 4077ms 0.4ms 174.4MB 3957ms 103ms ruby 3.2.0
ruby 1.rb timeout 0.0ms 414.1MB 9210ms 220ms truffleruby 22.3.1

lru

Input: 1000 1000000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
rust 0-unsafe.rs 58ms 2.0ms 1.1MB 50ms 0ms rustc 1.67.0
rust 1.rs 74ms 0.5ms 1.0MB 63ms 0ms rustc 1.67.0
ruby 1.rb 467ms 3.7ms 33.0MB 430ms 23ms ruby/yjit 3.2.0
ruby 1.rb 670ms 10ms 32.4MB 637ms 13ms ruby 3.2.0
ruby 1-m.rb 892ms 15ms 329.9MB 1300ms 120ms truffleruby 22.3.1

Input: 1000 3000000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
rust 0-unsafe.rs 195ms 7.8ms 1.0MB 180ms 0ms rustc 1.67.0
rust 1.rs 296ms 0.9ms 1.0MB 283ms 0ms rustc 1.67.0
ruby 1.rb 1239ms 3.7ms 32.9MB 1210ms 13ms ruby/yjit 3.2.0
ruby 1.rb 1672ms 87ms 359.1MB 2143ms 143ms truffleruby 22.3.1
ruby 1.rb 1812ms 11ms 32.4MB 1783ms 13ms ruby 3.2.0

Input: 100 500000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
rust 0-unsafe.rs 33ms 1.1ms 1.7MB 20ms 0ms rustc 1.67.0
rust 1.rs 48ms 0.4ms 1.1MB 40ms 0ms rustc 1.67.0
ruby 1.rb 270ms 0.7ms 32.9MB 240ms 13ms ruby/yjit 3.2.0
ruby 1.rb 371ms 2.0ms 32.3MB 340ms 17ms ruby 3.2.0
ruby 1-m.rb 639ms 18ms 319.0MB 957ms 107ms truffleruby 22.3.1

merkletrees

Input: 17

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
rust 1.rs 949ms 11ms 34.0MB 920ms 13ms rustc 1.67.0
ruby 1.rb timeout 0.0ms 96.5MB 4927ms 57ms ruby 3.2.0
ruby 1.rb timeout 0.0ms 97.1MB 4927ms 53ms ruby/yjit 3.2.0
ruby 1.rb timeout 0.0ms 515.5MB 9077ms 260ms truffleruby 22.3.1

Input: 15

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
rust 1.rs 192ms 1.1ms 9.9MB 180ms 0ms rustc 1.67.0
ruby 1.rb 3322ms 2877ms 52.8MB 4930ms 40ms ruby 3.2.0
ruby 1-m.rb 3712ms 39ms 590.9MB 6777ms 257ms truffleruby 22.3.1
ruby 1.rb 4121ms 6.3ms 53.6MB 4070ms 30ms ruby/yjit 3.2.0

nbody

Input: 5000000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
rust 4-i.rs 213ms 0.6ms 1.0MB 200ms 0ms rustc 1.67.0
rust 7-i.rs 310ms 0.5ms 1.1MB 300ms 0ms rustc 1.67.0
rust 2.rs 344ms 0.2ms 1.1MB 333ms 0ms rustc 1.67.0
rust 3.rs 347ms 1.3ms 1.1MB 330ms 0ms rustc 1.69.0-nightly
rust 1.rs 421ms 4.5ms 1.0MB 407ms 0ms rustc 1.67.0
ruby 2.rb 1216ms 34ms 313.2MB 1420ms 117ms truffleruby 22.3.1
ruby 2.rb timeout 0.0ms 32.1MB 4970ms 13ms ruby 3.2.0
ruby 2.rb timeout 0.0ms 33.0MB 4967ms 17ms ruby/yjit 3.2.0

Input: 500000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
rust 4-i.rs 24ms 0.3ms 1.0MB 10ms 0ms rustc 1.67.0
rust 7-i.rs 34ms 0.3ms 1.1MB 23ms 0ms rustc 1.67.0
rust 2.rs 37ms 0.1ms 1.0MB 27ms 0ms rustc 1.67.0
rust 3.rs 37ms 0.2ms 1.1MB 30ms 0ms rustc 1.69.0-nightly
rust 1.rs 45ms 0.6ms 1.0MB 33ms 0ms rustc 1.67.0
ruby 2-m.rb 452ms 38ms 311.2MB 690ms 93ms truffleruby 22.3.1
ruby 2.rb 2122ms 1.9ms 32.9MB 2093ms 13ms ruby/yjit 3.2.0
ruby 2.rb 3393ms 17ms 32.2MB 3363ms 17ms ruby 3.2.0

nsieve

Input: 12

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
rust 2.rs 460ms 4.8ms 6.6MB 443ms 3ms rustc 1.67.0
rust 1.rs 1406ms 28ms 40.7MB 1373ms 17ms rustc 1.67.0
ruby 1.rb timeout 0.0ms 344.6MB 4847ms 130ms ruby 3.2.0
ruby 1.rb timeout 0.0ms 345.0MB 4833ms 147ms ruby/yjit 3.2.0
ruby 1.rb timeout 0.0ms 684.4MB 5003ms 193ms truffleruby 22.3.1

Input: 10

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
rust 2.rs 102ms 1.2ms 3.1MB 90ms 0ms rustc 1.67.0
rust 1.rs 167ms 15ms 11.6MB 150ms 0ms rustc 1.67.0
ruby 1.rb 3311ms 25ms 430.9MB 3863ms 153ms 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.6MB 4913ms 63ms ruby/yjit 3.2.0

pidigits

Input: 8000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
rust 2.rs 1651ms 1.0ms 2.8MB 1583ms 47ms rustc 1.67.0
rust 1.rs 1705ms 3.0ms 2.8MB 1520ms 170ms rustc 1.67.0
ruby 1.rb timeout 0.0ms 157.8MB 4917ms 67ms ruby 3.2.0
ruby 1.rb timeout 0.0ms 158.5MB 4903ms 77ms ruby/yjit 3.2.0
ruby 1.rb timeout 0.0ms 431.5MB 9403ms 223ms truffleruby 22.3.1

Input: 4000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
rust 1.rs 368ms 1.1ms 2.5MB 350ms 7ms rustc 1.67.0
rust 2.rs 374ms 0.9ms 2.6MB 360ms 0ms rustc 1.67.0
ruby 1-m.rb 2269ms 60ms 418.2MB 4133ms 190ms truffleruby 22.3.1
ruby 1.rb 3194ms 6.2ms 158.6MB 3097ms 77ms ruby/yjit 3.2.0
ruby 1.rb 3219ms 10ms 157.8MB 3123ms 77ms ruby 3.2.0

spectral-norm

Input: 8000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
rust 8-m.rs 897ms 2.7ms 2.5MB 1733ms 0ms rustc 1.69.0-nightly
rust 7-m.rs 900ms 3.1ms 2.3MB 1733ms 3ms rustc 1.67.0
rust 8.rs 1724ms 0.3ms 2.4MB 1710ms 0ms rustc 1.69.0-nightly
rust 7.rs 1731ms 0.8ms 1.1MB 1717ms 0ms rustc 1.67.0
rust 2-m.rs 1827ms 1.5ms 2.3MB 3553ms 0ms rustc 1.67.0
ruby 4.rb timeout 0.0ms 32.1MB 4970ms 13ms ruby 3.2.0
ruby 4.rb timeout 0.0ms 32.8MB 4963ms 13ms ruby/yjit 3.2.0
ruby 4.rb timeout 0.0ms 389.6MB 5257ms 167ms truffleruby 22.3.1
rust 2.rs timeout 0.0ms 2.2MB 4987ms 0ms rustc 1.67.0

Input: 4000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
rust 8-m.rs 236ms 3.3ms 2.3MB 427ms 0ms rustc 1.69.0-nightly
rust 7-m.rs 238ms 2.4ms 1.0MB 430ms 0ms rustc 1.67.0
rust 8.rs 434ms 0.3ms 2.2MB 423ms 0ms rustc 1.69.0-nightly
rust 7.rs 436ms 0.4ms 1.1MB 427ms 0ms rustc 1.67.0
rust 2-m.rs 481ms 9.7ms 2.1MB 897ms 0ms rustc 1.67.0
rust 2.rs 1631ms 3.2ms 1.1MB 1620ms 0ms rustc 1.67.0
ruby 4.rb timeout 0.0ms 32.2MB 4973ms 7ms ruby 3.2.0
ruby 4.rb timeout 0.0ms 32.8MB 4967ms 17ms ruby/yjit 3.2.0
ruby 4.rb timeout 0.0ms 457.7MB 5487ms 180ms truffleruby 22.3.1

Input: 2000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
rust 8-m.rs 65ms 1.0ms 1.0MB 107ms 0ms rustc 1.69.0-nightly
rust 7-m.rs 66ms 2.1ms 1.1MB 103ms 0ms rustc 1.67.0
rust 8.rs 111ms 0.3ms 1.0MB 100ms 0ms rustc 1.69.0-nightly
rust 7.rs 111ms 0.4ms 1.8MB 100ms 0ms rustc 1.67.0
rust 2-m.rs 125ms 0.4ms 1.0MB 220ms 0ms rustc 1.67.0
rust 2.rs 410ms 0.4ms 1.0MB 400ms 0ms rustc 1.67.0
ruby 4.rb 2875ms 14ms 407.1MB 3453ms 140ms truffleruby 22.3.1
ruby 4.rb timeout 0.0ms 32.4MB 4970ms 10ms ruby 3.2.0
ruby 4.rb timeout 0.0ms 32.8MB 4970ms 10ms ruby/yjit 3.2.0