Swift VS Rust benchmarks

Current benchmark data was generated on Wed Jan 22 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
rust 4.rs 1246ms 3.8ms 33.8MB 1220ms 13ms rustc 1.84.0
rust 5.rs 1349ms 11ms 33.8MB 1327ms 7ms rustc 1.84.0
rust 3.rs 1475ms 58ms 49.8MB 1443ms 17ms rustc 1.84.0
swift 1.swift 2911ms 5.8ms 53.9MB 2883ms 17ms swift 6.0.3

Input: 15

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
rust 4.rs 122ms 1.4ms 5.8MB 110ms 0ms rustc 1.84.0
rust 5.rs 124ms 0.7ms 5.8MB 110ms 0ms rustc 1.84.0
rust 3.rs 139ms 4.3ms 7.8MB 123ms 3ms rustc 1.84.0
swift 1.swift 239ms 4.8ms 12.0MB 220ms 0ms swift 6.0.3

fannkuch-redux

Input: 11

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
rust 3-im.rs 411ms 1.6ms 4.0MB 1577ms 0ms rustc 1.84.0
rust 5-m.rs 566ms 8.3ms 4.0MB 2153ms 0ms rustc 1.84.0
rust 2-im.rs 629ms 8.2ms 4.0MB 2403ms 3ms rustc 1.84.0
rust 1-m.rs 967ms 7.9ms 4.0MB 3727ms 0ms rustc 1.84.0
rust 3-i.rs 1495ms 5.0ms 1.9MB 1483ms 0ms rustc 1.84.0
rust 2-i.rs 1759ms 3.0ms 1.8MB 1750ms 0ms rustc 1.84.0
swift 1.swift 2463ms 9.5ms 5.6MB 2450ms 0ms swift 6.0.3
rust 1.rs 2665ms 2.5ms 1.8MB 2657ms 0ms rustc 1.84.0

Input: 10

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
rust 3-im.rs 38ms 0.2ms 6.0MB 120ms 0ms rustc 1.84.0
rust 5-m.rs 56ms 3.5ms 4.0MB 170ms 0ms rustc 1.84.0
rust 2-im.rs 62ms 0.9ms 6.0MB 200ms 0ms rustc 1.84.0
rust 1-m.rs 86ms 1.8ms 6.0MB 300ms 0ms rustc 1.84.0
rust 3-i.rs 126ms 1.4ms 1.9MB 120ms 0ms rustc 1.84.0
rust 2-i.rs 149ms 0.9ms 1.8MB 140ms 0ms rustc 1.84.0
swift 1.swift 212ms 2.8ms 5.6MB 200ms 0ms swift 6.0.3
rust 1.rs 224ms 1.9ms 1.8MB 210ms 0ms rustc 1.84.0

fasta

Input: 2500000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
rust 5c-m.rs 88ms 0.2ms 6.5MB 233ms 3ms rustc 1.84.0
rust 5-m.rs 98ms 2.1ms 4.8MB 310ms 3ms rustc 1.84.0
swift 3-m.swift 140ms 3.0ms 24.8MB 380ms 3ms swift 6.0.3
rust 1c.rs 163ms 1.0ms 1.9MB 153ms 0ms rustc 1.84.0
rust 1.rs 204ms 1.5ms 1.9MB 190ms 0ms rustc 1.84.0

Input: 250000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
rust 5c-m.rs 16ms 0.2ms 4.8MB 23ms 0ms rustc 1.84.0
rust 5-m.rs 17ms 0.4ms 6.5MB 20ms 7ms rustc 1.84.0
rust 1c.rs 19ms 0.5ms 1.9MB 10ms 0ms rustc 1.84.0
rust 1.rs 23ms 0.1ms 1.9MB 10ms 0ms rustc 1.84.0
swift 3.swift 37ms 0.2ms 18.1MB 33ms 0ms swift 6.0.3

helloworld

Input: QwQ

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
rust 1.rs 1.2ms 0.0ms 1.9MB 0ms 0ms rustc 1.84.0
rust 1.rs 1.3ms 0.1ms 1.8MB 0ms 0ms rustc 1.86.0-nightly
swift 1.swift 2.3ms 0.2ms 6.0MB 0ms 0ms swift 6.0.3

knucleotide

Input: 2500000_in

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
rust 8-m.rs 241ms 8.1ms 30.2MB 700ms 3ms rustc 1.84.0
rust 8.rs 482ms 4.7ms 23.8MB 463ms 3ms rustc 1.84.0
swift 2-m.swift 1401ms 19ms 72.6MB 5030ms 33ms swift 6.0.3

Input: 250000_in

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
rust 8-m.rs 32ms 2.6ms 16.2MB 63ms 7ms rustc 1.84.0
rust 8.rs 70ms 5.7ms 11.4MB 57ms 0ms rustc 1.84.0
swift 2-m.swift 262ms 2.8ms 63.8MB 687ms 20ms swift 6.0.3

nbody

Input: 5000000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
rust 4-i.rs 167ms 7.9ms 1.9MB 153ms 0ms rustc 1.84.0
rust 7-i.rs 236ms 0.8ms 1.9MB 227ms 0ms rustc 1.84.0
rust 1.rs 239ms 0.8ms 1.8MB 230ms 0ms rustc 1.84.0
rust 2.rs 279ms 1.1ms 1.8MB 267ms 0ms rustc 1.84.0
rust 3.rs 280ms 0.3ms 1.9MB 267ms 0ms rustc 1.86.0-nightly
swift 7.swift 344ms 2.5ms 9.8MB 330ms 0ms swift 6.0.3

Input: 500000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
rust 4-i.rs 21ms 3.7ms 1.8MB 10ms 0ms rustc 1.84.0
rust 7-i.rs 26ms 0.4ms 1.8MB 20ms 0ms rustc 1.84.0
rust 1.rs 26ms 0.5ms 1.9MB 17ms 0ms rustc 1.84.0
rust 2.rs 30ms 0.2ms 1.8MB 20ms 0ms rustc 1.84.0
rust 3.rs 30ms 0.2ms 1.8MB 20ms 0ms rustc 1.86.0-nightly
swift 7.swift 39ms 1.1ms 9.8MB 30ms 0ms swift 6.0.3

pidigits

Input: 8000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
rust 1.rs 1530ms 9.8ms 2.7MB 1270ms 237ms rustc 1.84.0
rust 2.rs 1713ms 10ms 2.8MB 1610ms 90ms rustc 1.84.0
swift 1.swift timeout 0.0ms 7.1MB 4907ms 77ms swift 6.0.3

Input: 4000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
rust 1.rs 323ms 2.8ms 2.4MB 287ms 17ms rustc 1.84.0
rust 2.rs 380ms 2.1ms 2.5MB 370ms 0ms rustc 1.84.0
swift 1.swift 1861ms 13ms 6.9MB 1840ms 3ms swift 6.0.3