Ruby VS Java 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
java 2.java 741ms 67ms 604.5MB 693ms 140ms openjdk 20
java 2.java 785ms 70ms 601.6MB 723ms 153ms openjdk 19
java 2.java 929ms 77ms 665.9MB 940ms 233ms graal/jvm 17.0.6
java 2.java 1459ms 59ms 1085.7MB 960ms 723ms openjdk/zgc 19
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
java 2.java 187ms 22ms 108.8MB 167ms 37ms openjdk 20
java 2.java 192ms 10ms 111.6MB 187ms 33ms openjdk 19
java 2.java 204ms 15ms 162.8MB 223ms 60ms graal/jvm 17.0.6
java 2.java 346ms 6.2ms 239.6MB 207ms 167ms openjdk/zgc 19
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
java 1-m.java 3410ms 117ms 198.3MB 6373ms 130ms openjdk 19
ruby 1.rb 4122ms 30ms 82.7MB 4040ms 63ms ruby/yjit 3.2.0
java 1-m.java 4472ms 132ms 924.9MB 7827ms 667ms openjdk/zgc 19
java 1.java timeout 0.0ms 143.3MB 9577ms 97ms openjdk 20
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
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
java 1-m.java 854ms 61ms 112.8MB 1507ms 50ms openjdk 19
java 1-m.java 907ms 79ms 112.3MB 1597ms 60ms openjdk 20
java 1-m.java 1004ms 94ms 238.1MB 1497ms 207ms openjdk/zgc 19
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
java 4.java 472ms 15ms 40.5MB 540ms 20ms openjdk 20
java 4.java 477ms 7.5ms 43.4MB 550ms 10ms openjdk 19
java 4.java 536ms 5.5ms 41.8MB 547ms 73ms openjdk/zgc 19
java 4.java 555ms 7.5ms 97.9MB 757ms 33ms graal/jvm 17.0.6
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
java 4.java 151ms 4.9ms 40.7MB 160ms 13ms openjdk 19
java 4.java 152ms 14ms 39.8MB 170ms 13ms openjdk 20
java 4.java 159ms 10ms 86.3MB 180ms 30ms graal/jvm 17.0.6
java 4.java 210ms 11ms 41.2MB 170ms 70ms openjdk/zgc 19
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
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
java 1.java 80ms 2.1ms 48.1MB 72ms 14ms graal/jvm 17.0.6
ruby 1.rb 81ms 1.0ms 32.2MB 54ms 16ms ruby 3.2.0
java 1.java 87ms 9.2ms 39.3MB 78ms 16ms openjdk 20
java 1.java 93ms 4.7ms 42.4MB 76ms 24ms openjdk 19
java 1.java 150ms 9.1ms 41.0MB 86ms 64ms openjdk/zgc 19

json-serde

Input: sample 5000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
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
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
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
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
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
java 1.java 578ms 25ms 374.6MB 570ms 107ms openjdk 20
java 1.java 599ms 5.4ms 373.3MB 597ms 100ms openjdk 19
java 1.java 607ms 1.8ms 351.7MB 767ms 110ms graal/jvm 17.0.6
java 1.java 1062ms 7.0ms 737.3MB 673ms 530ms openjdk/zgc 19
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
java 1.java 259ms 11ms 174.3MB 250ms 63ms openjdk 19
java 1.java 264ms 11ms 222.1MB 263ms 60ms openjdk 20
java 1-m.java 301ms 2.6ms 279.6MB 410ms 60ms graal/jvm 17.0.6
java 1.java 460ms 1.7ms 307.8MB 270ms 230ms openjdk/zgc 19
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
java 1.java 599ms 11ms 89.9MB 623ms 27ms graal/jvm 17.0.6
java 1.java 651ms 5.4ms 40.6MB 660ms 10ms openjdk 20
java 1.java 661ms 11ms 42.0MB 657ms 23ms openjdk 19
java 1.java 707ms 18ms 41.7MB 650ms 70ms openjdk/zgc 19
ruby 2.rb 1216ms 34ms 313.2MB 1420ms 117ms truffleruby 22.3.1
java 2.java 2110ms 21ms 516.4MB 2083ms 167ms openjdk 20
java 2.java 2163ms 14ms 550.9MB 2123ms 173ms openjdk 19
java 2.java 2913ms 129ms 1417.8MB 2140ms 963ms openjdk/zgc 19
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
java 1.java 160ms 6.0ms 40.5MB 167ms 23ms openjdk 20
java 1.java 163ms 3.2ms 89.9MB 190ms 30ms graal/jvm 17.0.6
java 1.java 178ms 5.1ms 42.0MB 170ms 23ms openjdk 19
java 1.java 217ms 7.7ms 43.8MB 173ms 63ms openjdk/zgc 19
ruby 2-m.rb 452ms 38ms 311.2MB 690ms 93ms truffleruby 22.3.1
java 2.java 460ms 1.3ms 347.4MB 490ms 107ms openjdk 20
java 2.java 488ms 15ms 362.6MB 517ms 107ms openjdk 19
java 2.java 793ms 2.4ms 487.0MB 563ms 377ms openjdk/zgc 19
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
java 2.java 1038ms 8.7ms 51.3MB 1070ms 17ms openjdk 20
java 2.java 1088ms 7.3ms 52.3MB 1120ms 13ms openjdk 19
java 2.java 1148ms 3.8ms 50.8MB 1113ms 70ms openjdk/zgc 19
java 1.java 1206ms 75ms 84.4MB 1220ms 27ms openjdk 20
java 1.java 1465ms 36ms 112.2MB 1410ms 100ms openjdk/zgc 19
java 1.java 1523ms 26ms 85.7MB 1543ms 37ms openjdk 19
java 1.java 1999ms 39ms 241.2MB 2777ms 97ms graal/jvm 17.0.6
java 2-m.java 2014ms 153ms 290.9MB 3543ms 103ms graal/jvm 17.0.6
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
java 1.java 252ms 6.8ms 58.4MB 257ms 27ms openjdk 20
java 1.java 278ms 6.4ms 62.3MB 297ms 20ms openjdk 19
java 1.java 317ms 7.7ms 59.1MB 280ms 77ms openjdk/zgc 19
java 2.java 327ms 6.3ms 45.0MB 343ms 27ms openjdk 20
java 2.java 352ms 5.7ms 48.4MB 370ms 27ms openjdk 19
java 1.java 378ms 15ms 153.4MB 497ms 57ms graal/jvm 17.0.6
java 2.java 397ms 1.2ms 44.5MB 360ms 70ms openjdk/zgc 19
java 2-m.java 686ms 8.1ms 156.4MB 1170ms 77ms graal/jvm 17.0.6
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
java 1.java timeout 0.0ms 331.1MB 5447ms 97ms graal/jvm 17.0.6
java 1.java timeout 0.0ms 284.6MB 5387ms 110ms openjdk 19
java 1.java timeout 0.0ms 270.7MB 5410ms 100ms openjdk 20
java 1.java timeout 0.0ms 1375.1MB 4547ms 903ms openjdk/zgc 19
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
java 1.java 1451ms 18ms 261.6MB 1790ms 90ms openjdk 19
java 1.java 1458ms 14ms 295.9MB 1767ms 100ms openjdk 20
java 1.java 1543ms 16ms 342.7MB 1893ms 113ms graal/jvm 17.0.6
java 1.java 2059ms 27ms 987.0MB 1660ms 750ms openjdk/zgc 19
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
java 2-m.java 4353ms 35ms 91.0MB 8370ms 40ms graal/jvm 17.0.6
java 2.java timeout 0.0ms 44.0MB 9700ms 27ms openjdk 19
java 2.java timeout 0.0ms 40.6MB 9707ms 23ms openjdk 20
java 2.java timeout 0.0ms 43.9MB 9613ms 57ms openjdk/zgc 19
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

Input: 4000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
java 2-m.java 1256ms 17ms 93.9MB 2293ms 27ms graal/jvm 17.0.6
java 2-m.java 1690ms 21ms 44.1MB 3167ms 20ms openjdk 19
java 2-m.java 1719ms 55ms 42.2MB 3123ms 70ms openjdk/zgc 19
java 2-m.java 1964ms 48ms 40.9MB 3727ms 17ms openjdk 20
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
java 2-m.java 443ms 28ms 90.8MB 740ms 30ms graal/jvm 17.0.6
java 2-m.java 583ms 44ms 42.6MB 1013ms 17ms openjdk 19
java 2-m.java 603ms 35ms 40.7MB 1057ms 17ms openjdk 20
java 2-m.java 636ms 27ms 42.1MB 1000ms 70ms openjdk/zgc 19
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