Swift VS Ruby benchmarks

Current benchmark data was generated on Tue Mar 25 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-m.rb 1604ms 2779ms 798.2MB 6547ms 637ms truffleruby 24.2.0
swift 1.swift 2950ms 76ms 53.9MB 2917ms 20ms swift 6.0.3
ruby 1.rb 4929ms 11ms 110.0MB 4830ms 87ms ruby/yjit 3.4.2
ruby 1.rb timeout 0.0ms 70.6MB 4943ms 43ms ruby 3.4.2

Input: 15

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
swift 1.swift 237ms 1.1ms 11.9MB 227ms 0ms swift 6.0.3
ruby 1.rb 497ms 4.3ms 20.3MB 473ms 10ms ruby/yjit 3.4.2
ruby 1-m.rb 605ms 52ms 425.3MB 1203ms 173ms truffleruby 24.2.0
ruby 1.rb 935ms 7.2ms 19.6MB 910ms 10ms ruby 3.4.2

fannkuch-redux

Input: 11

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
swift 1.swift 2483ms 17ms 5.6MB 2473ms 0ms swift 6.0.3

Input: 10

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
swift 1.swift 214ms 1.8ms 6.3MB 207ms 0ms swift 6.0.3

fasta

Input: 2500000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
swift 3-m.swift 135ms 1.1ms 20.9MB 387ms 0ms swift 6.0.3
ruby 6.rb 2067ms 17ms 23.0MB 2040ms 13ms ruby/yjit 3.4.2
ruby 6-m.rb 2128ms 75ms 365.9MB 5427ms 350ms truffleruby 24.2.0
ruby 6.rb 3896ms 43ms 22.5MB 3870ms 17ms ruby 3.4.2

Input: 250000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
swift 3.swift 36ms 0.3ms 18.3MB 30ms 0ms swift 6.0.3
ruby 6.rb 262ms 3.7ms 15.0MB 243ms 7ms ruby/yjit 3.4.2
ruby 6.rb 440ms 7.9ms 14.5MB 420ms 3ms ruby 3.4.2
ruby 6-m.rb 787ms 58ms 380.4MB 1943ms 177ms truffleruby 24.2.0

helloworld

Input: QwQ

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
swift 1.swift 2.5ms 0.2ms 5.9MB 0ms 0ms swift 6.0.3
ruby 1.rb 38ms 1.6ms 142.2MB 14ms 28ms truffleruby 24.2.0
ruby 1.rb 52ms 1.2ms 12.9MB 38ms 4ms ruby 3.4.2
ruby 1.rb 54ms 2.1ms 13.0MB 40ms 2ms ruby/yjit 3.4.2

knucleotide

Input: 2500000_in

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
swift 2-m.swift 1390ms 6.6ms 74.5MB 5083ms 30ms swift 6.0.3

Input: 250000_in

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
swift 2-m.swift 263ms 1.7ms 60.0MB 693ms 23ms swift 6.0.3

nbody

Input: 5000000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
swift 7.swift 345ms 1.2ms 9.8MB 340ms 0ms swift 6.0.3
ruby 2.rb 846ms 5.3ms 311.6MB 1087ms 127ms truffleruby 24.2.0
ruby 2.rb timeout 0.0ms 12.9MB 4983ms 7ms ruby 3.4.2
ruby 2.rb timeout 0.0ms 13.5MB 4987ms 0ms ruby/yjit 3.4.2

Input: 500000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
swift 7.swift 40ms 0.2ms 9.8MB 30ms 0ms swift 6.0.3
ruby 2-m.rb 313ms 8.1ms 310.0MB 540ms 123ms truffleruby 24.2.0
ruby 2.rb 1065ms 2.9ms 13.5MB 1043ms 0ms ruby/yjit 3.4.2
ruby 2.rb 2836ms 76ms 12.9MB 2817ms 3ms 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 4920ms 67ms ruby 3.4.2
ruby 1.rb timeout 0.0ms 123.9MB 4887ms 100ms ruby/yjit 3.4.2
ruby 1.rb timeout 0.0ms 457.3MB 13323ms 400ms truffleruby 24.2.0
swift 1.swift timeout 0.0ms 7.1MB 4910ms 70ms swift 6.0.3

Input: 4000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
ruby 1.rb 1685ms 6.0ms 46.0MB 1633ms 37ms ruby 3.4.2
ruby 1-m.rb 1729ms 252ms 405.1MB 4537ms 220ms truffleruby 24.2.0
ruby 1.rb 1798ms 0.8ms 127.8MB 1647ms 133ms ruby/yjit 3.4.2
swift 1.swift 1877ms 8.7ms 7.0MB 1863ms 0ms swift 6.0.3