Java VS Ruby benchmarks

Current benchmark data was generated on Sat Jan 28 2023, full log can be found HERE

CONTRIBUTIONS are WELCOME!

[x86_64][2 cores] Intel(R) Xeon(R) Platinum 8370C CPU @ 2.80GHz (Model 106)

* -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 665ms 6.1ms 412.0MB 690ms 70ms openjdk 20
java 2.java 719ms 58ms 602.2MB 703ms 117ms openjdk 19
java 2.java 760ms 59ms 667.2MB 823ms 147ms graal/jvm 17.0.6
java 2.java 1276ms 25ms 1068.3MB 903ms 577ms openjdk/zgc 19
ruby 1.rb timeout 0.0ms 72.6MB 4943ms 40ms ruby 3.2.0
ruby 1.rb timeout 0.0ms 115.6MB 4917ms 60ms ruby/yjit 3.2.0
ruby 1.rb timeout 0.0ms 612.7MB 8020ms 290ms truffleruby 22.3.1

Input: 15

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
java 2.java 167ms 1.7ms 109.0MB 167ms 30ms openjdk 19
java 2.java 169ms 16ms 108.4MB 163ms 20ms openjdk 20
java 2-m.java 172ms 3.9ms 157.8MB 217ms 43ms graal/jvm 17.0.6
java 2.java 295ms 1.6ms 248.7MB 197ms 137ms openjdk/zgc 19
ruby 1.rb 565ms 6.7ms 40.7MB 530ms 17ms ruby/yjit 3.2.0
ruby 1.rb 1011ms 5.8ms 40.3MB 973ms 20ms ruby 3.2.0
ruby 1-m.rb 1081ms 25ms 419.3MB 1780ms 140ms truffleruby 22.3.1

edigits

Input: 250001

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
java 1-m.java 778ms 13ms 204.8MB 1363ms 63ms openjdk 20
java 1-m.java 846ms 64ms 301.8MB 1367ms 70ms graal/jvm 17.0.6
java 1-m.java 877ms 15ms 199.6MB 1570ms 57ms openjdk 19
java 1-m.java 1013ms 13ms 429.1MB 1507ms 290ms openjdk/zgc 19

Input: 100000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
java 1-m.java 367ms 12ms 159.9MB 603ms 50ms graal/jvm 17.0.6
java 1-m.java 441ms 18ms 118.0MB 737ms 23ms openjdk 19
java 1-m.java 466ms 5.9ms 115.5MB 780ms 40ms openjdk 20
java 1-m.java 550ms 40ms 209.2MB 790ms 137ms openjdk/zgc 19

fannkuch-redux

Input: 11

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
java 1-m.java 1668ms 10ms 95.1MB 3183ms 20ms graal/jvm 17.0.6
java 1-m.java 1741ms 6.4ms 43.8MB 3257ms 50ms openjdk/zgc 19
java 1-m.java 1751ms 36ms 43.7MB 3357ms 20ms openjdk 19
java 1-m.java 1789ms 119ms 41.1MB 3427ms 10ms openjdk 20

Input: 10

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
java 1-m.java 277ms 4.7ms 43.6MB 440ms 20ms openjdk 19
java 1-m.java 278ms 2.5ms 40.5MB 453ms 7ms openjdk 20
java 1-m.java 283ms 4.5ms 90.9MB 463ms 10ms graal/jvm 17.0.6
java 1-m.java 321ms 3.3ms 43.8MB 440ms 57ms openjdk/zgc 19

fasta

Input: 2500000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
java 4.java 515ms 1.8ms 40.7MB 587ms 10ms openjdk 20
java 4.java 523ms 4.9ms 42.2MB 587ms 17ms openjdk 19
java 4.java 561ms 7.1ms 43.3MB 583ms 57ms openjdk/zgc 19
java 4.java 617ms 8.7ms 99.3MB 793ms 30ms graal/jvm 17.0.6
ruby 6.rb 2359ms 2.6ms 43.6MB 2327ms 17ms ruby/yjit 3.2.0
ruby 6-m.rb 2687ms 54ms 389.5MB 4817ms 267ms truffleruby 22.3.1
ruby 6.rb 4361ms 91ms 43.0MB 4323ms 20ms ruby 3.2.0

Input: 250000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
java 4.java 151ms 6.6ms 41.0MB 173ms 10ms openjdk 19
java 4.java 155ms 11ms 89.1MB 203ms 17ms graal/jvm 17.0.6
java 4.java 155ms 5.7ms 40.1MB 183ms 7ms openjdk 20
java 4.java 191ms 4.0ms 41.1MB 167ms 50ms openjdk/zgc 19
ruby 6.rb 313ms 1.0ms 34.9MB 287ms 13ms ruby/yjit 3.2.0
ruby 6.rb 502ms 1.2ms 34.4MB 467ms 20ms ruby 3.2.0
ruby 6-m.rb 887ms 40ms 341.9MB 1497ms 120ms truffleruby 22.3.1

helloworld

Input: QwQ

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
ruby 1.rb 45ms 2.4ms 154.4MB 18ms 30ms truffleruby 22.3.1
ruby 1.rb 72ms 1.0ms 32.2MB 50ms 10ms ruby 3.2.0
java 1.java 76ms 6.2ms 63.1MB 70ms 10ms graal/jvm 17.0.6
ruby 1.rb 77ms 0.9ms 32.3MB 50ms 12ms ruby/yjit 3.2.0
java 1.java 79ms 3.3ms 39.3MB 74ms 10ms openjdk 20
java 1.java 81ms 3.7ms 41.3MB 76ms 8ms openjdk 19
java 1.java 119ms 4.3ms 39.7MB 76ms 48ms openjdk/zgc 19

knucleotide

Input: 2500000_in

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
java 3-m.java 1450ms 24ms 113.3MB 2653ms 33ms openjdk 20
java 3-m.java 1455ms 8.2ms 116.8MB 2667ms 33ms openjdk 19
java 3-m.java 1562ms 78ms 169.4MB 2877ms 47ms graal/jvm 17.0.6
java 3-m.java 1982ms 73ms 174.2MB 3517ms 120ms openjdk/zgc 19

Input: 250000_in

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
java 3-m.java 444ms 36ms 87.4MB 730ms 30ms openjdk 20
java 3-m.java 473ms 46ms 96.2MB 803ms 27ms openjdk 19
java 3-m.java 487ms 49ms 139.1MB 790ms 50ms graal/jvm 17.0.6
java 3-m.java 490ms 25ms 96.3MB 743ms 87ms openjdk/zgc 19

mandelbrot

Input: 5000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
java 1b.java 1420ms 19ms 48.3MB 1510ms 17ms openjdk 19
java 1b.java 1423ms 14ms 47.0MB 1507ms 20ms openjdk 20
java 1b.java 1456ms 25ms 108.3MB 1617ms 47ms graal/jvm 17.0.6
java 1b.java 1460ms 14ms 48.8MB 1513ms 53ms openjdk/zgc 19
java 1a.java 1533ms 4.6ms 48.4MB 1597ms 20ms openjdk 19
java 1a.java 1544ms 4.9ms 47.5MB 1620ms 13ms openjdk 20
java 1a.java 1566ms 5.9ms 99.4MB 1637ms 40ms graal/jvm 17.0.6
java 1a.java 1580ms 6.9ms 49.3MB 1610ms 53ms openjdk/zgc 19
java 1.java 2007ms 7.7ms 135.6MB 2093ms 30ms graal/jvm 17.0.6
java 1.java 2113ms 8.6ms 208.1MB 2147ms 47ms openjdk 20
java 1.java 2140ms 25ms 190.1MB 2187ms 47ms openjdk 19
java 1.java 2498ms 7.7ms 578.7MB 2253ms 333ms openjdk/zgc 19
java 2.java timeout 0.0ms 526.6MB 5170ms 110ms openjdk 19
java 2.java timeout 0.0ms 575.3MB 5157ms 120ms openjdk 20
java 2.java timeout 0.0ms 1227.2MB 4887ms 573ms openjdk/zgc 19

Input: 1000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
java 1b.java 208ms 16ms 43.2MB 277ms 7ms openjdk 20
java 1a.java 219ms 12ms 48.3MB 300ms 13ms openjdk 19
java 1a.java 220ms 16ms 43.6MB 300ms 7ms openjdk 20
java 1.java 224ms 7.6ms 96.8MB 273ms 20ms openjdk 19
java 1a.java 225ms 11ms 92.2MB 287ms 27ms graal/jvm 17.0.6
java 1b.java 226ms 15ms 46.4MB 290ms 13ms openjdk 19
java 1.java 228ms 9.6ms 95.3MB 270ms 20ms openjdk 20
java 1.java 247ms 19ms 124.2MB 343ms 27ms graal/jvm 17.0.6
java 1a.java 252ms 8.5ms 45.1MB 257ms 57ms openjdk/zgc 19
java 1b-m.java 259ms 19ms 98.7MB 390ms 27ms graal/jvm 17.0.6
java 1b.java 264ms 4.2ms 45.4MB 293ms 50ms openjdk/zgc 19
java 1.java 288ms 1.8ms 111.3MB 287ms 77ms openjdk/zgc 19
java 2.java 767ms 32ms 532.3MB 950ms 133ms openjdk 19
java 2.java 769ms 20ms 581.5MB 960ms 113ms openjdk 20
java 2.java 1331ms 80ms 1038.9MB 1020ms 583ms openjdk/zgc 19

merkletrees

Input: 17

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
java 1.java 505ms 22ms 369.4MB 543ms 47ms openjdk 19
java 1.java 534ms 50ms 290.5MB 547ms 53ms openjdk 20
java 1.java 574ms 78ms 352.8MB 723ms 90ms graal/jvm 17.0.6
java 1.java 951ms 43ms 764.9MB 647ms 437ms openjdk/zgc 19
ruby 1.rb timeout 0.0ms 96.4MB 4933ms 47ms ruby 3.2.0
ruby 1.rb timeout 0.0ms 97.0MB 4927ms 57ms ruby/yjit 3.2.0
ruby 1.rb timeout 0.0ms 562.9MB 9010ms 220ms truffleruby 22.3.1

Input: 15

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
java 1.java 216ms 5.7ms 173.4MB 240ms 30ms openjdk 19
java 1.java 234ms 11ms 222.3MB 227ms 57ms openjdk 20
java 1-m.java 270ms 4.6ms 281.7MB 367ms 67ms graal/jvm 17.0.6
java 1.java 432ms 11ms 354.8MB 253ms 223ms openjdk/zgc 19
ruby 1-m.rb 3464ms 95ms 580.1MB 6290ms 240ms truffleruby 22.3.1
ruby 1.rb 4125ms 19ms 53.7MB 4087ms 23ms ruby/yjit 3.2.0
ruby 1.rb 4936ms 27ms 52.7MB 4890ms 23ms ruby 3.2.0

nbody

Input: 5000000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
java 1.java 542ms 2.3ms 88.2MB 563ms 23ms graal/jvm 17.0.6
java 1.java 565ms 6.7ms 40.5MB 563ms 20ms openjdk 20
java 1.java 568ms 4.5ms 44.3MB 573ms 10ms openjdk 19
java 1.java 613ms 5.8ms 41.9MB 580ms 50ms openjdk/zgc 19
ruby 2.rb 1036ms 17ms 305.8MB 1233ms 93ms truffleruby 22.3.1
java 2.java 1881ms 18ms 552.6MB 1900ms 113ms openjdk 20
java 2.java 1893ms 4.6ms 532.8MB 1910ms 107ms openjdk 19
java 2.java 2574ms 9.2ms 1220.9MB 1993ms 770ms openjdk/zgc 19
ruby 2.rb timeout 0.0ms 32.1MB 4977ms 7ms ruby 3.2.0
ruby 2.rb timeout 0.0ms 33.0MB 4973ms 10ms ruby/yjit 3.2.0

Input: 500000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
java 1.java 137ms 1.3ms 86.0MB 163ms 23ms graal/jvm 17.0.6
java 1.java 144ms 3.4ms 42.3MB 157ms 10ms openjdk 19
java 1.java 149ms 7.7ms 40.7MB 160ms 10ms openjdk 20
java 1.java 191ms 2.6ms 44.1MB 160ms 50ms openjdk/zgc 19
java 2.java 414ms 6.8ms 335.1MB 487ms 63ms openjdk 19
java 2.java 416ms 8.0ms 338.5MB 477ms 67ms openjdk 20
ruby 2-m.rb 471ms 46ms 316.8MB 680ms 137ms truffleruby 22.3.1
java 2.java 701ms 44ms 528.8MB 540ms 313ms openjdk/zgc 19
ruby 2.rb 2176ms 4.7ms 33.0MB 2153ms 7ms ruby/yjit 3.2.0
ruby 2.rb 3381ms 35ms 32.3MB 3360ms 3ms ruby 3.2.0

nsieve

Input: 12

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
java 1.java 658ms 16ms 85.7MB 683ms 17ms openjdk 19
java 1.java 780ms 41ms 84.9MB 797ms 30ms openjdk 20
java 1.java 906ms 5.7ms 112.0MB 847ms 80ms openjdk/zgc 19
java 2.java 1003ms 6.2ms 50.6MB 1043ms 13ms openjdk 20
java 2.java 1017ms 5.7ms 54.0MB 1050ms 7ms openjdk 19
java 2.java 1027ms 2.0ms 50.5MB 1007ms 57ms openjdk/zgc 19
java 1-m.java 1131ms 52ms 244.6MB 1700ms 87ms graal/jvm 17.0.6
java 2-m.java 1840ms 116ms 286.4MB 3240ms 110ms graal/jvm 17.0.6
ruby 1.rb timeout 0.0ms 344.6MB 4840ms 133ms ruby 3.2.0
ruby 1.rb timeout 0.0ms 345.0MB 4827ms 150ms ruby/yjit 3.2.0
ruby 1.rb timeout 0.0ms 685.1MB 5010ms 183ms truffleruby 22.3.1

Input: 10

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
java 1.java 236ms 3.3ms 61.7MB 253ms 23ms openjdk 19
java 1.java 239ms 7.2ms 58.4MB 260ms 13ms openjdk 20
java 1.java 284ms 2.1ms 60.7MB 260ms 60ms openjdk/zgc 19
java 2.java 327ms 2.5ms 45.1MB 360ms 10ms openjdk 20
java 2.java 328ms 1.3ms 49.7MB 350ms 17ms openjdk 19
java 1-m.java 338ms 2.6ms 149.3MB 483ms 40ms graal/jvm 17.0.6
java 2.java 359ms 6.6ms 43.9MB 343ms 50ms openjdk/zgc 19
java 2-m.java 614ms 3.5ms 152.0MB 1087ms 47ms graal/jvm 17.0.6
ruby 1.rb 3156ms 53ms 419.9MB 3677ms 137ms truffleruby 22.3.1
ruby 1.rb timeout 0.0ms 151.0MB 4920ms 53ms ruby 3.2.0
ruby 1.rb timeout 0.0ms 151.5MB 4923ms 57ms 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 4919ms 11ms 360.4MB 5340ms 87ms graal/jvm 17.0.6
java 1.java timeout 0.0ms 239.2MB 5423ms 90ms openjdk 19
java 1.java timeout 0.0ms 279.2MB 5390ms 80ms openjdk 20
java 1.java timeout 0.0ms 1254.0MB 5003ms 670ms openjdk/zgc 19
ruby 1.rb timeout 0.0ms 157.9MB 4937ms 47ms ruby 3.2.0
ruby 1.rb timeout 0.0ms 159.9MB 4923ms 53ms ruby/yjit 3.2.0
ruby 1.rb timeout 0.0ms 461.5MB 9333ms 257ms truffleruby 22.3.1

Input: 4000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
java 1.java 1341ms 31ms 311.6MB 1660ms 80ms graal/jvm 17.0.6
java 1.java 1424ms 19ms 274.6MB 1790ms 63ms openjdk 19
java 1.java 1452ms 11ms 294.2MB 1840ms 70ms openjdk 20
java 1.java 1943ms 14ms 917.6MB 1850ms 570ms openjdk/zgc 19
ruby 1-m.rb 2020ms 26ms 435.4MB 3657ms 173ms truffleruby 22.3.1
ruby 1.rb 2424ms 8.0ms 158.0MB 2343ms 63ms ruby 3.2.0
ruby 1.rb 2426ms 8.8ms 159.8MB 2343ms 67ms ruby/yjit 3.2.0

regex-redux

Input: 2500000_in

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
java 3.java timeout 0.0ms 251.6MB 5297ms 53ms graal/jvm 17.0.6
java 3.java timeout 0.0ms 205.8MB 5240ms 70ms openjdk 19
java 3.java timeout 0.0ms 204.2MB 5250ms 63ms openjdk 20
java 3.java timeout 0.0ms 337.4MB 4960ms 220ms openjdk/zgc 19

Input: 250000_in

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
java 3.java 1031ms 22ms 171.4MB 1417ms 47ms graal/jvm 17.0.6
java 3.java 1061ms 34ms 109.9MB 1380ms 37ms openjdk 19
java 3.java 1064ms 6.8ms 114.5MB 1403ms 27ms openjdk 20
java 3.java 1191ms 24ms 157.7MB 1353ms 120ms openjdk/zgc 19

spectral-norm

Input: 8000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
java 2-m.java 4207ms 116ms 89.8MB 8140ms 20ms graal/jvm 17.0.6
java 2.java timeout 0.0ms 46.0MB 9730ms 17ms openjdk 19
java 2.java timeout 0.0ms 40.7MB 9717ms 13ms openjdk 20
java 2.java timeout 0.0ms 41.8MB 9627ms 43ms openjdk/zgc 19
ruby 4.rb timeout 0.0ms 32.1MB 4967ms 13ms ruby 3.2.0
ruby 4.rb timeout 0.0ms 32.8MB 4970ms 13ms ruby/yjit 3.2.0
ruby 4.rb timeout 0.0ms 566.4MB 5240ms 247ms truffleruby 22.3.1

Input: 4000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
java 2-m.java 1208ms 43ms 91.2MB 2237ms 27ms graal/jvm 17.0.6
java 2-m.java 1621ms 30ms 44.3MB 3063ms 17ms openjdk 19
java 2-m.java 1721ms 70ms 40.9MB 3273ms 10ms openjdk 20
java 2-m.java 1769ms 188ms 42.1MB 3277ms 53ms openjdk/zgc 19
ruby 4.rb timeout 0.0ms 32.2MB 4973ms 10ms ruby 3.2.0
ruby 4.rb timeout 0.0ms 32.8MB 4973ms 13ms ruby/yjit 3.2.0
ruby 4.rb timeout 0.0ms 562.1MB 5453ms 223ms truffleruby 22.3.1

Input: 2000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
java 2-m.java 435ms 21ms 89.1MB 727ms 33ms graal/jvm 17.0.6
java 2-m.java 552ms 40ms 41.0MB 977ms 13ms openjdk 20
java 2-m.java 589ms 38ms 44.3MB 1043ms 10ms openjdk 19
java 2-m.java 636ms 31ms 43.9MB 1040ms 57ms openjdk/zgc 19
ruby 4.rb 2585ms 15ms 476.7MB 3107ms 167ms truffleruby 22.3.1
ruby 4.rb timeout 0.0ms 32.4MB 4967ms 10ms ruby 3.2.0
ruby 4.rb timeout 0.0ms 32.7MB 4967ms 13ms ruby/yjit 3.2.0

coro-prime-sieve

Input: 4000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
java 1-m.java 1079ms 1868ms 169.2MB 8467ms 113ms openjdk 19
ruby 1.rb 3205ms 134ms 82.8MB 3133ms 50ms ruby/yjit 3.2.0
ruby 1.rb 3867ms 456ms 82.1MB 3787ms 60ms ruby 3.2.0
java 1-m.java 4163ms 65ms 906.7MB 7423ms 537ms openjdk/zgc 19
java 1.java timeout 0.0ms 139.7MB 9567ms 47ms openjdk 20
ruby 1.rb timeout 0.0ms 942.2MB 4210ms 1413ms truffleruby 22.3.1

Input: 1000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
ruby 1.rb 231ms 3.0ms 44.9MB 190ms 27ms ruby/yjit 3.2.0
ruby 1.rb 240ms 0.5ms 44.5MB 203ms 20ms ruby 3.2.0
java 1-m.java 766ms 114ms 112.0MB 1377ms 37ms openjdk 20
java 1-m.java 817ms 154ms 113.2MB 1453ms 47ms openjdk 19
java 1-m.java 950ms 24ms 315.6MB 1520ms 173ms openjdk/zgc 19
ruby 1.rb timeout 0.0ms 908.0MB 4197ms 1183ms truffleruby 22.3.1