Ruby VS Java benchmarks

Current benchmark data was generated on Mon Dec 30 2024, 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
java 2.java 470ms 5.2ms 643.8MB 573ms 93ms openjdk 23
java 2-m.java 503ms 33ms 647.1MB 723ms 113ms graal/jvm 17.0.8
java 2.java 523ms 24ms 572.1MB 573ms 123ms openjdk 21
java 2.java 1179ms 21ms 1061.1MB 597ms 750ms openjdk/zgc 21
ruby 1-m.rb 4559ms 99ms 826.4MB 6440ms 460ms truffleruby 24.1.1
ruby 1.rb 4582ms 104ms 110.1MB 4487ms 73ms ruby/yjit 3.4.1
ruby 1.rb timeout 0.0ms 70.5MB 4947ms 37ms ruby 3.4.1

Input: 15

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
java 2.java 121ms 3.7ms 167.1MB 147ms 33ms openjdk 21
java 2.java 127ms 6.0ms 98.3MB 160ms 30ms openjdk 23
java 2-m.java 147ms 3.6ms 217.2MB 217ms 50ms graal/jvm 17.0.8
java 2.java 308ms 0.7ms 241.5MB 150ms 210ms openjdk/zgc 21
ruby 1.rb 478ms 0.9ms 20.4MB 450ms 20ms ruby/yjit 3.4.1
ruby 1-m.rb 600ms 8.2ms 437.8MB 1227ms 167ms truffleruby 24.1.1
ruby 1.rb 940ms 8.6ms 19.6MB 913ms 10ms ruby 3.4.1

coro-prime-sieve

Input: 4000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
ruby 1.rb 1426ms 6.5ms 63.9MB 1353ms 57ms ruby/yjit 3.4.1
java 1-m.java 1774ms 162ms 260.9MB 6640ms 123ms openjdk 21
ruby 1.rb 1877ms 44ms 63.1MB 1780ms 83ms ruby 3.4.1
java 1-m.java 2359ms 176ms 242.2MB 8950ms 137ms openjdk 23
java 1-m.java 2678ms 125ms 1210.6MB 8550ms 1040ms openjdk/zgc 21
ruby 1.rb timeout 0.0ms 725.4MB 4653ms 1547ms truffleruby 24.1.1

Input: 1000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
ruby 1.rb 155ms 1.0ms 25.8MB 123ms 17ms ruby/yjit 3.4.1
ruby 1.rb 178ms 2.1ms 25.1MB 143ms 17ms ruby 3.4.1
java 1-m.java 399ms 60ms 94.6MB 1303ms 47ms openjdk 23
java 1-m.java 407ms 34ms 120.2MB 1323ms 70ms openjdk 21
java 1-m.java 641ms 37ms 215.7MB 1710ms 250ms openjdk/zgc 21
ruby 1.rb timeout 0.0ms 741.3MB 4710ms 1493ms truffleruby 24.1.1

fasta

Input: 2500000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
java 4.java 451ms 5.2ms 47.6MB 530ms 20ms openjdk 21
java 4.java 454ms 3.6ms 49.0MB 547ms 10ms openjdk 23
java 4-m.java 463ms 14ms 105.1MB 660ms 40ms graal/jvm 17.0.8
java 4.java 563ms 2.0ms 46.9MB 530ms 133ms openjdk/zgc 21
ruby 6.rb 2042ms 9.8ms 23.1MB 2013ms 10ms ruby/yjit 3.4.1
ruby 6-m.rb 2044ms 111ms 402.5MB 5243ms 363ms truffleruby 24.1.1
ruby 6.rb 3669ms 34ms 22.5MB 3643ms 10ms ruby 3.4.1

Input: 250000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
java 4.java 125ms 0.4ms 46.8MB 163ms 17ms openjdk 21
java 4.java 125ms 0.6ms 47.6MB 173ms 10ms openjdk 23
java 4-m.java 132ms 11ms 97.1MB 180ms 37ms graal/jvm 17.0.8
java 4.java 238ms 8.8ms 43.8MB 153ms 140ms openjdk/zgc 21
ruby 6.rb 256ms 0.8ms 15.2MB 230ms 13ms ruby/yjit 3.4.1
ruby 6.rb 419ms 6.7ms 14.5MB 400ms 7ms ruby 3.4.1
ruby 6-m.rb 819ms 5.3ms 387.6MB 1987ms 200ms truffleruby 24.1.1

helloworld

Input: QwQ

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
ruby 1.rb 39ms 0.5ms 165.1MB 12ms 32ms truffleruby 24.1.1
ruby 1.rb 51ms 1.2ms 13.1MB 38ms 2ms ruby/yjit 3.4.1
ruby 1.rb 53ms 0.7ms 12.9MB 40ms 4ms ruby 3.4.1
java 1.java 63ms 1.7ms 54.7MB 60ms 22ms graal/jvm 17.0.8
java 1.java 66ms 3.8ms 43.8MB 70ms 18ms openjdk 21
java 1.java 68ms 6.1ms 44.7MB 76ms 12ms openjdk 23
java 1.java 187ms 4.7ms 44.6MB 78ms 132ms openjdk/zgc 21

json-serde

Input: sample 5000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
ruby 1.rb 247ms 1.2ms 28.6MB 217ms 20ms ruby 3.4.1
ruby 1.rb 250ms 5.0ms 31.1MB 217ms 17ms ruby/yjit 3.4.1
ruby 1-m.rb 4304ms 152ms 528.0MB 11207ms 323ms truffleruby 24.1.1

Input: canada 15

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
ruby 1.rb 2089ms 23ms 134.4MB 1993ms 80ms ruby 3.4.1
ruby 1.rb 2090ms 42ms 135.4MB 2010ms 67ms ruby/yjit 3.4.1
ruby 1.rb timeout 0.0ms 595.9MB 13137ms 367ms truffleruby 24.1.1

lru

Input: 1000 1000000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
ruby 1.rb 330ms 1.9ms 13.6MB 307ms 10ms ruby/yjit 3.4.1
ruby 1.rb 537ms 2.5ms 13.0MB 523ms 3ms ruby 3.4.1
ruby 1-m.rb 717ms 35ms 391.9MB 1247ms 167ms truffleruby 24.1.1

Input: 1000 3000000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
ruby 1.rb 882ms 5.3ms 13.6MB 853ms 17ms ruby/yjit 3.4.1
ruby 1-m.rb 1201ms 51ms 421.0MB 1657ms 177ms truffleruby 24.1.1
ruby 1.rb 1493ms 8.9ms 12.9MB 1473ms 7ms ruby 3.4.1

Input: 100 500000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
ruby 1.rb 196ms 4.3ms 13.5MB 177ms 3ms ruby/yjit 3.4.1
ruby 1.rb 292ms 5.8ms 12.9MB 273ms 0ms ruby 3.4.1
ruby 1-m.rb 515ms 25ms 371.7MB 1013ms 110ms truffleruby 24.1.1

merkletrees

Input: 17

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
java 1.java 399ms 1.4ms 542.0MB 487ms 93ms openjdk 23
java 1.java 423ms 3.2ms 678.0MB 463ms 120ms openjdk 21
java 1-m.java 432ms 28ms 579.8MB 670ms 87ms graal/jvm 17.0.8
java 1.java 1051ms 32ms 963.0MB 460ms 717ms openjdk/zgc 21
ruby 1-m.rb 4577ms 143ms 578.9MB 11673ms 380ms truffleruby 24.1.1
ruby 1.rb timeout 0.0ms 94.0MB 4940ms 40ms ruby 3.4.1
ruby 1.rb timeout 0.0ms 97.5MB 4920ms 63ms ruby/yjit 3.4.1

Input: 15

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
java 1-m.java 161ms 1.6ms 206.3MB 240ms 30ms openjdk 21
java 1-m.java 162ms 2.8ms 158.4MB 233ms 40ms openjdk 23
java 1-m.java 233ms 27ms 259.4MB 393ms 53ms graal/jvm 17.0.8
java 1.java 416ms 29ms 341.8MB 207ms 283ms openjdk/zgc 21
ruby 1-m.rb 2187ms 101ms 525.8MB 5677ms 230ms truffleruby 24.1.1
ruby 1.rb 3238ms 7.5ms 38.4MB 3203ms 17ms ruby/yjit 3.4.1
ruby 1.rb 4306ms 3.3ms 37.8MB 4267ms 23ms ruby 3.4.1

nbody

Input: 5000000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
java 1.java 440ms 1.4ms 45.1MB 480ms 17ms openjdk 21
java 1.java 442ms 1.9ms 48.1MB 480ms 10ms openjdk 23
java 1.java 448ms 9.7ms 84.8MB 477ms 23ms graal/jvm 17.0.8
java 1.java 564ms 1.4ms 44.6MB 477ms 143ms openjdk/zgc 21
ruby 2.rb 835ms 6.7ms 327.0MB 1073ms 117ms truffleruby 24.1.1
java 2.java 1225ms 6.3ms 537.4MB 1353ms 73ms openjdk 21
java 2.java 1260ms 20ms 715.9MB 1367ms 110ms openjdk 23
java 2.java 3206ms 52ms 2355.0MB 1643ms 1770ms openjdk/zgc 21
ruby 2.rb timeout 0.0ms 12.9MB 4980ms 3ms ruby 3.4.1
ruby 2.rb timeout 0.0ms 13.6MB 4980ms 3ms ruby/yjit 3.4.1

Input: 500000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
java 1.java 118ms 1.6ms 45.3MB 157ms 17ms openjdk 21
java 1.java 122ms 0.2ms 48.4MB 160ms 10ms openjdk 23
java 1-m.java 122ms 5.7ms 95.3MB 160ms 30ms graal/jvm 17.0.8
java 1.java 245ms 1.2ms 44.5MB 160ms 143ms openjdk/zgc 21
java 2-m.java 296ms 5.5ms 346.7MB 430ms 57ms openjdk 21
java 2-m.java 298ms 3.8ms 394.1MB 427ms 70ms openjdk 23
ruby 2-m.rb 322ms 4.0ms 333.7MB 590ms 100ms truffleruby 24.1.1
java 2.java 682ms 11ms 527.4MB 467ms 393ms openjdk/zgc 21
ruby 2.rb 1053ms 5.8ms 13.6MB 1037ms 3ms ruby/yjit 3.4.1
ruby 2.rb 2816ms 74ms 12.9MB 2800ms 3ms ruby 3.4.1

nsieve

Input: 12

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
java 1.java 391ms 1.1ms 115.8MB 443ms 20ms openjdk 21
java 1.java 392ms 5.2ms 118.3MB 427ms 30ms openjdk 23
java 1.java 570ms 10.0ms 112.7MB 470ms 170ms openjdk/zgc 21
java 1-m.java 588ms 6.1ms 209.4MB 843ms 73ms graal/jvm 17.0.8
java 2.java 771ms 0.6ms 57.5MB 827ms 17ms openjdk 21
java 2.java 780ms 1.5ms 60.4MB 823ms 20ms openjdk 23
java 2.java 837ms 5.8ms 55.2MB 767ms 137ms openjdk/zgc 21
java 2-m.java 1402ms 78ms 263.6MB 2503ms 113ms graal/jvm 17.0.8
ruby 1.rb timeout 0.0ms 325.4MB 4850ms 133ms ruby 3.4.1
ruby 1.rb timeout 0.0ms 327.1MB 4843ms 133ms ruby/yjit 3.4.1
ruby 1.rb timeout 0.0ms 762.9MB 5063ms 167ms truffleruby 24.1.1

Input: 10

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
java 1.java 153ms 3.0ms 64.5MB 190ms 27ms openjdk 21
java 1.java 156ms 7.2ms 68.1MB 203ms 20ms openjdk 23
java 1-m.java 201ms 5.1ms 130.4MB 277ms 43ms graal/jvm 17.0.8
java 2.java 260ms 2.7ms 50.8MB 303ms 20ms openjdk 23
java 2.java 260ms 1.2ms 49.6MB 313ms 20ms openjdk 21
java 1.java 281ms 1.4ms 61.6MB 200ms 143ms openjdk/zgc 21
java 2.java 366ms 1.1ms 49.6MB 303ms 140ms openjdk/zgc 21
java 2-m.java 555ms 44ms 205.4MB 983ms 77ms graal/jvm 17.0.8
ruby 1-m.rb 1740ms 47ms 486.8MB 2463ms 153ms truffleruby 24.1.1
ruby 1.rb 3441ms 129ms 131.9MB 3357ms 70ms ruby/yjit 3.4.1
ruby 1.rb 4493ms 12ms 131.1MB 4407ms 73ms ruby 3.4.1

pidigits

Input: 8000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
java 1.java 3168ms 1.6ms 445.4MB 3600ms 83ms graal/jvm 17.0.8
java 1.java 3621ms 25ms 412.3MB 4497ms 110ms openjdk 23
java 1.java 3704ms 51ms 351.8MB 4517ms 123ms openjdk 21
java 1.java timeout 0.0ms 1977.1MB 4647ms 1220ms openjdk/zgc 21
ruby 1.rb timeout 0.0ms 46.5MB 4910ms 77ms ruby 3.4.1
ruby 1.rb timeout 0.0ms 47.2MB 4937ms 47ms ruby/yjit 3.4.1
ruby 1.rb timeout 0.0ms 467.9MB 13150ms 400ms truffleruby 24.1.1

Input: 4000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
java 1.java 906ms 26ms 373.8MB 1277ms 77ms graal/jvm 17.0.8
java 1-m.java 1002ms 33ms 351.1MB 1813ms 80ms openjdk 21
java 1-m.java 1037ms 4.5ms 395.1MB 1743ms 97ms openjdk 23
ruby 1.rb 1638ms 12ms 46.1MB 1587ms 37ms ruby 3.4.1
ruby 1.rb 1713ms 72ms 127.8MB 1603ms 93ms ruby/yjit 3.4.1
ruby 1-m.rb 1790ms 18ms 406.6MB 4713ms 200ms truffleruby 24.1.1
java 1.java 2001ms 40ms 1342.4MB 1710ms 1033ms openjdk/zgc 21

spectral-norm

Input: 8000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
java 2-m.java 1954ms 2.3ms 47.6MB 7430ms 27ms openjdk 21
java 2-m.java 1957ms 10.0ms 48.4MB 7443ms 27ms openjdk 23
java 2-m.java 2087ms 15ms 47.8MB 7507ms 150ms openjdk/zgc 21
java 2-m.java 2463ms 18ms 101.0MB 8780ms 43ms graal/jvm 17.0.8
ruby 4.rb timeout 0.0ms 13.0MB 4980ms 3ms ruby 3.4.1
ruby 4.rb timeout 0.0ms 13.6MB 4980ms 7ms ruby/yjit 3.4.1
ruby 4.rb timeout 0.0ms 467.6MB 5170ms 207ms truffleruby 24.1.1

Input: 4000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
java 2-m.java 581ms 3.1ms 48.0MB 2053ms 13ms openjdk 21
java 2-m.java 590ms 3.1ms 48.8MB 2057ms 23ms openjdk 23
java 2-m.java 712ms 6.8ms 47.4MB 2073ms 143ms openjdk/zgc 21
java 2-m.java 730ms 13ms 100.2MB 2463ms 43ms graal/jvm 17.0.8
ruby 4.rb 4492ms 21ms 467.4MB 4820ms 187ms truffleruby 24.1.1
ruby 4.rb timeout 0.0ms 13.0MB 4980ms 3ms ruby 3.4.1
ruby 4.rb timeout 0.0ms 13.6MB 4973ms 13ms ruby/yjit 3.4.1

Input: 2000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
java 2-m.java 235ms 9.8ms 47.9MB 683ms 17ms openjdk 21
java 2-m.java 238ms 3.7ms 48.8MB 667ms 27ms openjdk 23
java 2-m.java 282ms 17ms 99.0MB 820ms 43ms graal/jvm 17.0.8
java 2-m.java 360ms 7.4ms 47.0MB 673ms 150ms openjdk/zgc 21
ruby 4.rb 1289ms 48ms 390.0MB 1640ms 137ms truffleruby 24.1.1
ruby 4.rb timeout 0.0ms 13.0MB 4983ms 7ms ruby 3.4.1
ruby 4.rb timeout 0.0ms 13.9MB 4980ms 3ms ruby/yjit 3.4.1