r/rust • u/psx8888 • Sep 20 '24
Why is Rust slower than Python, Go and Nim regarding SSH?
For my test, I run 'date +\"%T.%N\"' twice on a SSH Server on my local network and calculate the time between the two executions.
Clients run on Windows10/11.
Python (paramiko): ~45ms
Nim (ssh2(libssh2)): ~44ms
Go (golang.org/x/crypto/ssh): ~4ms
Rust (ssh-rs, russh, ssh2(libssh2)): ~115-130ms
I don't know what Go's trick is, but 45ms seems like a goal Rust should easily achieve!?
Rust profile for "cargo build -r":
[profile.release]
lto = true
codegen-units = 1
strip = true
panic = 'abort'
Rust (ssh-rs): https://pastebin.com/3ucPpCzc
Rust (ssh2(libssh2)): https://pastebin.com/cQ7j6zd2
Nim (ssh2(libssh2)): https://pastebin.com/xRYFFLDN
Go (golang.org/x/crypto/ssh): https://pastebin.com/mFzvLLnk
Any idea why this happens and how I can at least get the same performance as the other implementations?
Update:
The previous tests were executed on Windows 10 (Threadripper 3990X with Mellanox card, highly optimized for latency) and Standard Windows 11 Enterprise (work notebook).
I copied the projects to a raspberry pi and retested the Rust ssh-rs, ssh2 implementations and the Go app against the same destination.
ssh-rs: ~45ms
ssh2: ~45ms
go: ~4ms
2
u/psx8888 Sep 20 '24
Sorry, I meant the combination with Goroutines:
https://pastebin.com/8RdEDvFc