Ruby VS C benchmarks

Current benchmark data was generated on Mon Mar 31 2025, 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
ruby 1.rb 4874ms 16ms 109.4MB 4770ms 90ms ruby/yjit 3.4.2
ruby 1.rb timeout 0.0ms 70.1MB 4937ms 43ms ruby 3.4.2
ruby 1.rb timeout 0.0ms 793.7MB 6597ms 650ms truffleruby 24.2.0

Input: 15

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
ruby 1.rb 494ms 2.7ms 20.3MB 470ms 10ms ruby/yjit 3.4.2
ruby 1-m.rb 575ms 60ms 422.2MB 1147ms 167ms truffleruby 24.2.0
ruby 1.rb 937ms 6.7ms 19.6MB 910ms 13ms ruby 3.4.2

coro-prime-sieve

Input: 4000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
ruby 1.rb 1478ms 22ms 63.8MB 1397ms 67ms ruby/yjit 3.4.2
ruby 1.rb 1855ms 2.6ms 63.1MB 1780ms 60ms ruby 3.4.2
ruby 1.rb timeout 0.0ms 347.0MB 4763ms 1433ms truffleruby 24.2.0

Input: 1000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
ruby 1.rb 159ms 1.0ms 25.6MB 127ms 17ms ruby/yjit 3.4.2
ruby 1.rb 185ms 1.3ms 25.1MB 153ms 17ms ruby 3.4.2
ruby 1.rb timeout 0.0ms 353.2MB 4600ms 1553ms truffleruby 24.2.0

fasta

Input: 2500000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
ruby 6.rb 2060ms 10ms 23.0MB 2030ms 13ms ruby/yjit 3.4.2
ruby 6-m.rb 2165ms 97ms 405.7MB 5593ms 363ms truffleruby 24.2.0
ruby 6.rb 3848ms 36ms 22.5MB 3820ms 10ms ruby 3.4.2

Input: 250000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
ruby 6.rb 266ms 4.3ms 15.0MB 247ms 10ms ruby/yjit 3.4.2
ruby 6.rb 437ms 2.4ms 14.5MB 420ms 7ms ruby 3.4.2
ruby 6-m.rb 815ms 10ms 363.4MB 2020ms 177ms truffleruby 24.2.0

helloworld

Input: QwQ

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
c 1.c 1.1ms 0.1ms 1.4MB 0ms 0ms zigcc 0.14.0
c 1.c 1.3ms 0.1ms 2.1MB 0ms 0ms gcc 14.2.0
c 1.c 1.3ms 0.0ms 2.1MB 0ms 0ms clang 14.0.0-1ubuntu1.1
ruby 1.rb 35ms 0.4ms 142.2MB 14ms 28ms truffleruby 24.2.0
ruby 1.rb 52ms 3.5ms 12.9MB 34ms 2ms ruby 3.4.2
ruby 1.rb 53ms 0.9ms 13.0MB 34ms 6ms ruby/yjit 3.4.2

json-serde

Input: sample 5000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
ruby 1.rb 252ms 3.6ms 29.1MB 220ms 20ms ruby 3.4.2
ruby 1.rb 256ms 3.5ms 28.4MB 227ms 17ms ruby/yjit 3.4.2
ruby 1-m.rb 4493ms 172ms 518.1MB 11833ms 350ms truffleruby 24.2.0

Input: canada 15

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
ruby 1.rb 2091ms 5.7ms 132.7MB 2000ms 77ms ruby 3.4.2
ruby 1.rb 2116ms 29ms 135.1MB 2017ms 83ms ruby/yjit 3.4.2
ruby 1.rb timeout 0.0ms 495.0MB 13197ms 370ms truffleruby 24.2.0

lru

Input: 1000 1000000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
ruby 1.rb 338ms 2.7ms 13.5MB 320ms 7ms ruby/yjit 3.4.2
ruby 1.rb 534ms 7.9ms 13.0MB 517ms 7ms ruby 3.4.2
ruby 1-m.rb 679ms 33ms 375.8MB 1217ms 147ms truffleruby 24.2.0

Input: 1000 3000000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
ruby 1.rb 880ms 3.0ms 13.5MB 857ms 7ms ruby/yjit 3.4.2
ruby 1-m.rb 1252ms 51ms 416.2MB 1803ms 183ms truffleruby 24.2.0
ruby 1.rb 1490ms 12ms 13.0MB 1470ms 7ms ruby 3.4.2

Input: 100 500000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
ruby 1.rb 196ms 2.7ms 13.5MB 177ms 7ms ruby/yjit 3.4.2
ruby 1.rb 292ms 5.2ms 12.9MB 273ms 0ms ruby 3.4.2
ruby 1-m.rb 513ms 36ms 360.4MB 1000ms 140ms truffleruby 24.2.0

merkletrees

Input: 17

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
ruby 1-m.rb 4071ms 251ms 628.9MB 10250ms 363ms truffleruby 24.2.0
ruby 1.rb timeout 0.0ms 94.3MB 4930ms 50ms ruby 3.4.2
ruby 1.rb timeout 0.0ms 94.8MB 4937ms 50ms ruby/yjit 3.4.2

Input: 15

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
ruby 1-m.rb 2113ms 104ms 582.3MB 5393ms 277ms truffleruby 24.2.0
ruby 1.rb 3439ms 28ms 38.3MB 3403ms 23ms ruby/yjit 3.4.2
ruby 1.rb 4410ms 17ms 37.8MB 4373ms 23ms ruby 3.4.2

nbody

Input: 5000000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
c 8-i.c 273ms 4.4ms 1.5MB 263ms 0ms zigcc 0.14.0
c 8-i.c 302ms 1.2ms 2.1MB 293ms 0ms clang 14.0.0-1ubuntu1.1
c 2.c 311ms 1.2ms 2.3MB 300ms 0ms gcc 14.2.0
c 5.c 314ms 1.5ms 2.3MB 300ms 0ms gcc 14.2.0
c 2.c 315ms 1.9ms 1.5MB 310ms 0ms zigcc 0.14.0
c 5.c 316ms 0.5ms 2.1MB 307ms 0ms clang 14.0.0-1ubuntu1.1
c 5.c 316ms 1.1ms 1.5MB 310ms 0ms zigcc 0.14.0
c 2.c 318ms 2.1ms 2.1MB 310ms 0ms clang 14.0.0-1ubuntu1.1
c 8-i.c 332ms 0.8ms 2.3MB 323ms 0ms gcc 14.2.0
ruby 2.rb 830ms 8.7ms 322.7MB 1090ms 113ms truffleruby 24.2.0
ruby 2.rb timeout 0.0ms 12.9MB 4987ms 0ms ruby 3.4.2
ruby 2.rb timeout 0.0ms 13.5MB 4980ms 3ms ruby/yjit 3.4.2

Input: 500000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
c 8-i.c 29ms 0.4ms 1.5MB 20ms 0ms zigcc 0.14.0
c 8-i.c 33ms 0.5ms 2.1MB 27ms 0ms clang 14.0.0-1ubuntu1.1
c 2.c 34ms 1.0ms 1.5MB 30ms 0ms zigcc 0.14.0
c 5.c 34ms 0.5ms 2.3MB 30ms 0ms gcc 14.2.0
c 2.c 34ms 1.0ms 2.3MB 27ms 0ms gcc 14.2.0
c 5.c 34ms 0.6ms 2.1MB 30ms 0ms clang 14.0.0-1ubuntu1.1
c 5.c 34ms 0.5ms 1.5MB 30ms 0ms zigcc 0.14.0
c 8-i.c 36ms 0.1ms 2.3MB 30ms 0ms gcc 14.2.0
c 2.c 37ms 2.6ms 2.1MB 30ms 0ms clang 14.0.0-1ubuntu1.1
ruby 2-m.rb 310ms 2.6ms 310.1MB 543ms 113ms truffleruby 24.2.0
ruby 2.rb 1066ms 0.5ms 13.5MB 1047ms 3ms ruby/yjit 3.4.2
ruby 2.rb 2789ms 66ms 12.9MB 2773ms 0ms ruby 3.4.2

nsieve

Input: 12

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
c 1.c 252ms 2.1ms 41.0MB 237ms 0ms gcc 14.2.0
c 1.c 268ms 1.9ms 40.2MB 250ms 0ms zigcc 0.14.0
c 1.c 269ms 5.7ms 40.9MB 250ms 3ms clang 14.0.0-1ubuntu1.1
ruby 1.rb timeout 0.0ms 325.4MB 4847ms 140ms ruby 3.4.2
ruby 1.rb timeout 0.0ms 327.0MB 4853ms 137ms ruby/yjit 3.4.2
ruby 1.rb timeout 0.0ms 709.5MB 5073ms 150ms truffleruby 24.2.0

Input: 10

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
c 1.c 49ms 1.1ms 11.6MB 40ms 0ms gcc 14.2.0
c 1.c 53ms 2.9ms 11.5MB 40ms 0ms clang 14.0.0-1ubuntu1.1
c 1.c 57ms 3.1ms 11.0MB 47ms 0ms zigcc 0.14.0
ruby 1-m.rb 1735ms 26ms 487.2MB 2477ms 167ms truffleruby 24.2.0
ruby 1.rb 3439ms 35ms 131.8MB 3347ms 77ms ruby/yjit 3.4.2
ruby 1.rb 4550ms 60ms 131.1MB 4463ms 77ms ruby 3.4.2

pidigits

Input: 8000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
ruby 1.rb timeout 0.0ms 46.7MB 4923ms 67ms ruby 3.4.2
ruby 1.rb timeout 0.0ms 126.8MB 4890ms 100ms ruby/yjit 3.4.2
ruby 1.rb timeout 0.0ms 457.8MB 13330ms 427ms truffleruby 24.2.0

Input: 4000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
ruby 1-m.rb 1582ms 157ms 399.4MB 4173ms 207ms truffleruby 24.2.0
ruby 1.rb 1703ms 3.1ms 46.2MB 1657ms 33ms ruby 3.4.2
ruby 1.rb 1706ms 60ms 127.5MB 1643ms 50ms ruby/yjit 3.4.2

spectral-norm

Input: 8000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
c 6-im.c 951ms 9.5ms 2.0MB 3740ms 0ms gcc 14.2.0
c 4-m.c 968ms 1.5ms 2.0MB 3803ms 0ms gcc 14.2.0
c 6-im.c 1003ms 0.8ms 3.3MB 3940ms 0ms clang 14.0.0-1ubuntu1.1
c 5-im.c 1089ms 3.6ms 2.0MB 4287ms 3ms gcc 14.2.0
c 4-m.c 1129ms 14ms 3.3MB 4427ms 7ms clang 14.0.0-1ubuntu1.1
c 5-im.c 1335ms 7.2ms 3.3MB 5240ms 7ms clang 14.0.0-1ubuntu1.1
c 3-m.c 1849ms 16ms 3.4MB 7250ms 20ms clang 14.0.0-1ubuntu1.1
c 3-m.c 1980ms 13ms 2.0MB 7780ms 3ms gcc 14.2.0
ruby 4.rb timeout 0.0ms 13.0MB 4983ms 0ms ruby 3.4.2
ruby 4.rb timeout 0.0ms 13.5MB 4980ms 3ms ruby/yjit 3.4.2
ruby 4.rb timeout 0.0ms 463.4MB 5177ms 250ms truffleruby 24.2.0

Input: 4000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
c 6-im.c 248ms 5.1ms 2.0MB 953ms 0ms gcc 14.2.0
c 4-m.c 253ms 1.6ms 2.0MB 967ms 0ms gcc 14.2.0
c 6-im.c 259ms 1.4ms 3.3MB 990ms 0ms clang 14.0.0-1ubuntu1.1
c 5-im.c 290ms 15ms 2.0MB 1103ms 0ms gcc 14.2.0
c 4-m.c 294ms 9.2ms 3.3MB 1117ms 0ms clang 14.0.0-1ubuntu1.1
c 5-im.c 351ms 17ms 3.4MB 1333ms 0ms clang 14.0.0-1ubuntu1.1
c 3-m.c 468ms 7.2ms 3.3MB 1807ms 0ms clang 14.0.0-1ubuntu1.1
c 3-m.c 496ms 2.9ms 2.0MB 1933ms 0ms gcc 14.2.0
ruby 4.rb 4892ms 24ms 472.1MB 5177ms 213ms truffleruby 24.2.0
ruby 4.rb timeout 0.0ms 13.0MB 4980ms 0ms ruby 3.4.2
ruby 4.rb timeout 0.0ms 13.6MB 4980ms 0ms ruby/yjit 3.4.2

Input: 2000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
c 4-m.c 71ms 0.5ms 2.1MB 257ms 0ms gcc 14.2.0
c 6-im.c 73ms 2.6ms 3.3MB 250ms 0ms clang 14.0.0-1ubuntu1.1
c 6-im.c 73ms 6.2ms 2.0MB 257ms 0ms gcc 14.2.0
c 4-m.c 78ms 0.7ms 3.1MB 280ms 0ms clang 14.0.0-1ubuntu1.1
c 5-im.c 80ms 0.7ms 2.0MB 287ms 0ms gcc 14.2.0
c 5-im.c 93ms 0.7ms 3.3MB 330ms 0ms clang 14.0.0-1ubuntu1.1
c 3-m.c 124ms 1.1ms 3.1MB 453ms 0ms clang 14.0.0-1ubuntu1.1
c 3-m.c 131ms 0.9ms 2.0MB 490ms 0ms gcc 14.2.0
ruby 4.rb 1453ms 12ms 389.8MB 1777ms 143ms truffleruby 24.2.0
ruby 4.rb timeout 0.0ms 13.0MB 4980ms 0ms ruby 3.4.2
ruby 4.rb timeout 0.0ms 13.8MB 4983ms 0ms ruby/yjit 3.4.2