Rust vs. Go (Golang): Performance (Only Standard Library)
ฝัง
- เผยแพร่เมื่อ 6 ก.พ. 2025
- Go vs Rust Performance Comparison.
🔴 To support my channel, I'd like to offer Mentorship/On-the-Job Support/Consulting (me@antonputra.com)
🍿 Benchmarks: • New Benchmarks
👋 AWS is expensive - Infra Support Fund: buymeacoffee.c...
▬▬▬▬▬ Experience & Location 💼 ▬▬▬▬▬
► I’m a Senior Software Engineer at Juniper Networks (13+ years of experience)
► Located in San Francisco Bay Area, CA (US citizen)
▬▬▬▬▬▬ Connect with me 👋 ▬▬▬▬▬▬
► LinkedIn: / anton-putra
► Twitter/X: / antonvputra
► GitHub: github.com/ant...
► Email: me@antonputra.com
▬▬▬▬▬▬▬ Source Code 📚 ▬▬▬▬▬▬▬
► Original Source Code: github.com/ant...
PR to improve Rust - github.com/ant...
#deno #bun #nodejs
🔴 To support my channel, I'd like to offer Mentorship/On-the-Job Support/Consulting (me@antonputra.com)
🍿 Benchmarks: th-cam.com/play/PLiMWaCMwGJXmcDLvMQeORJ-j_jayKaLVn.html&si=p-UOaVM_6_SFx52H
👋 AWS is expensive - Infra Support Fund: buymeacoffee.com/antonputra
And now it's worth doing the same test using the fastest possible language-specific method.
@Jack-b4s3g techempower :-)
Rust benchmark without Tokio is like testing a Ferrari in 1st gear
Yes. Right now is not really an apple to apple comparison. More like programming skill comparison🤦♂
true, tokio is the best!
does ferrari comes with manual gear
@@ulrich-tonmoy Not sure about the relevency. Ferrari come with dual-clutch and manual. You can switch between the 2 modes. Certain models can have F1-automatic(I think you have to pay extra though.)
No it's not.
Tokio is awesome but it's not standard library. A stock Ferrari has more than one gear.
This is testing standard libraries as they both describe in their documentationS. That's a fair test IMHO
Rust doesnt have async runtime by default. Rust's std is design to be minimal, total opposed than Go.
@@Takatou__Yogiri then fair not to use Rust on server side
true, tokio next
@@yurcchello May be that's your opinion but many big companies are using rust in their servers.
It's neither fair or unfair. This comparison is artificially constrained in a way that the constraints would never be choosen by someone writing idiomatic rust. So in that sense this is mostly an irrelevant exercise.
For the kind of work I do, Rust takes longer to write and runs slower than Go. Workflows involving RPC, I/O, and networking favor Go, making it much easier to be productive. Rust shines at systems programming, CPU bound tasks, and hardware interfacing, which I rarely do. Right tool for the right job.
rust can be faster at io, he used threads for io bound task
And what do you do ? It's simply impossible for rust to run slower than a language with a crappy compiler that does 0 optimizations
Yeah if you need to get real work done fast, Go will be faster to write, compile and also run. And easier to maintain since Rust standard library is weak, you'll need third party dependencies in Rust to do even basic stuff that Go gives you for free. And Go standard library is maintained by Google top tier professional engineers.
@bcassol not true at all
@@bcassolwrite in Python if you need rapid development. Then optimize in C/C++/Rust
As always, very good. Thank you!
Go is simply The GOaT
Without so many sh!tty dependencies and without googling every line (because you can have all the language in your mind) you can write very competitive high performance software.
There's no better trade-off in software engineering landscape!
Mistery solved: the toy server in rust performs bad because it lacks support for keep alive. After turning off keep alive in go I get the very dame bad performance. Also, I get the same requests per second (60k) for the rust and go apps after implementing very rudimentary support for it
Thank you Anton for making these insightful comparison videos! They are very helpful and educational.
However, I would like to point out that this particular benchmark may not be entirely fair:
1. Go has built-in async runtime while this Rust implementation uses threads and mutex locks
2. The accept() is running in a single thread
3. The write operations lack buffering optimizations
These fundamental differences in implementation make it difficult to draw meaningful performance comparisons between the two approaches.
Perhaps a more apples-to-apples comparison would be to use async Rust (with tokio/async-std) or optimize the current implementation further.
Nevertheless, really appreciate the effort in creating these comparison videos! They help us learn a lot about different languages and approaches.
no matter what i chose simplicity
@mikejohneviota9293 go is not simple, it is simplified, and there is a huge difference
agreed
Visual basic FTW
Welp. Here is the difference between first straight forward naive approach vs industry standard tool with a decade of improvements. Bubble sort vs QuickSort. It's not the language.
true
Do Java vs C# broda
yes soon
Him using a semicolon instead of a colon in the timer feels wrong 😅
It’s like languages using periods for decimals lol
haha, i can't change it
Great to see a fair comparison after multiple videos comparing Go's standard lib to Rust's server lib. Now maybe do a test with 2-3 popular high-performance Go frameworks vs. some high-performance Rust ones.
At the end of the day, that's what people are using in production, so might as well test real tools and not just the basics.
Can you please make a video about Quarkus ( virtual threads ) vs Go vs Rust
Everyone is talking about how this test isn't fair but failing to read the title where it states specifically standard libraries. If you watch the video you would know his next benchmark video will be on tokio so you all can quit complaining.
Thank you so much for this amazing video! I have a quick question: My OKX wallet holds some USDT, and I have the seed phrase. (air carpet target dish off jeans toilet sweet piano spoil fruit essay). How can I transfer them to Binance?
I doubt the utility of this video to be honest as it is not really fair on so many levels. But at least it does highlight how good the stdlib of go is
If anything, it means to use the right tool for the right job.
There are applications where Go will excel over Rust and vice-versa.
I'm new to all of this, what is the unfairness here
Go is best 💪💪💪
@fortwentiblazeit4177 what are those applications ? The only thing that go excels at is attracting mediocrity
What is unfair here? I can spin up a concurrent server faster in Go than in Rust, and without extensive optimization, the Go server will handle more requests. There's a reason tools like Docker, Kubernetes, Grafana, and Prometheus were written in Go-it takes less time to be productive in Go, and for I/O-bound work, it can be faster than Rust in many scenarios.
Not a fair comparison. You're kinda comparing green thread vs os level thread. You will have to use async function in rust but then you need to use third party libraries to execute async functions.
The problem is that he is using very small thread pool (10) threads. If he was using a proeprly sized threadpool (200+), Rust would have easily achieved more TPS than golang. Green threads are not about performance, but about concurrency and the ability to cancel a running task, something which in certain case is not possible with threads
@@svetlinzarev3453 Why can't an os thread have "concurrency and the ability to cancel a running task"?
According to my understanding, green thread has less overhead thus creating and destroying multiple green threads takes less overhead than with os level threads.
@ahmedaghadi8281 for instance in Java, which also uses OS threads you cannot set a timeout or cancel a write operation on a socket. Simply there is no such api. Whime in async rust, you can simply stop polling the future
@@svetlinzarev3453stopping the poll does not necessarily guarantee cancelling the issued syscall before drop either no?
yes next is the tokio runtime
Can you do a test giving both apps at least 2 cpus and have them interact with Postgres?
there is already such test and Rust destroys golang by a lot
@ link?
they both have 2 cpu = m7a.large (2 cpu + 8 gig of memory)
Please give Nim a shot too. It is very easy to write and performs very well.
Does it have a server framework?
@@NathanielBabalola yes. Jester, Karax, Happyx and a bunch more.
Blud forgot the -release on the rust app 💀💀💀💀
haha
Thank you for the video. 🚀
Feel sorry for the rust fans crying in the comments.
well tell them to wait for the next one with async implemenration
Can you please make a video on fiber vs stdlib vs gin?
yes will update soon
@@AntonPutra Thank you ☺
Rust is better than Go. There seems to be a problem; it looks like you don’t understand much about Rust because many people know that Rust's performance is better than Go's.
Your multithreaded Rust has a memory leak (again)
So create PR and repair it
@@PanSzelescik Nahh. I'm already busy with other projects, like Mbin, sorry.
Where ?
Dude, I'm studying Rust from a book. I'd like to ask how you guys determine that there is a memory leak, so I can better understand whether this behavior is not standard in Rust or if it's the result of some implementation by you or someone else. It's my first low-level language; I'm studying it because I liked its syntax and I want to be as close as possible to the machine.
@@chacal4x1 SvetlinZarev already fixed it
looks like you forget --release for rust app
This is just a click bait video. For the views, it is missleading for new devs. That is why almost every reply he does is "tokio is next". I would rather watch a 10-15 vidoes of both, than a missleading 5 min video.
Now, in the future where people are looking for rust vs go for webserver, this thing will show up. You should delete this video, it is useless; and edit your tokio video and includes this one first. A least it woll give the viewer a real context to the video --never try to use rust standard kibrary for webserver-- right now this is just a useless, inclomplete, missleading video.
You will get the same min views if you just add it to your upcoming video.
Was this test fair? Yeah. Was it helpful? Not at all. absolutely nobody runs code configured like this.
it's not about rust but more about sync implementation, tokio next :)
It is about you2 algorithm and voews, that is why ot has to be in a separate video than the tokio one, even though he has made videos using the barebone and the framework of something together before, sad.
I like your videos but this one doesn't make any sense in this form. This a well-known thing that rust outperforms GO in every case. :| So this video is nothing more than just a clickbait one. :(
Use Jetty for Java along with the handlers it provides in a non-blocking mode. On the other side, put whatever you like. I promise you'll be amazed.
Nit: tags of the video are wrong (deno, bun, nodejs)
As always pretty through benchmark Anton. Next benchmark request: Laravel vs Nextjs vs Django. Pretty Please 🙏!
next is tokio but your request in the pipeline
Rust is great... in theory.
tokio is great
... in theory.
I'm of the opinion that it's not the best option for web development. Looking forward to the next video.
interesting. Although i knew network implementations of both languages standard liblary's are way more slower than their frameworks: this slowness of rust's stdlib is quite surprising.
it just lack async implementation that tokio provides
Can you please also benchmark "ship fast" languages such as Node.js vs Ruby on Rails vs Laravel vs Django etc..?
express or hono vs rails is better comparison.
i did in the past
@@AntonPutra That was a comparisson between node js vs rails. Why not compare express js vs rails?
if ur good a Rust it will be faster than anything, if ur bad at it will be slower than anything.
But GO is fast despite if ur good or bad.
Rust doesnt have a async runtime by default, so would be fair if u compare Rust+Tokio vs Go.
true, go is great for beginners and lazy programmers
Background song?
steps
Lol should have waited for 1.24 which is due this month 😆😆
soon
This is interesting test, but not conducted properly. Traditional webservers such apache tomcat that use a thread per request model use a large threadpool to compensate for io waiting. For instance, tomcat uses 200 threads by default. You should tweak the number of threads until you get at least 80 percent cpu utilization.
Love the insight about thread pools! Though even Tomcat's 200 threads hit I/O walls - that's why the Tokio benchmark will be super interesting to watch.
not true, i tried 4, 10, 100, 1000 and 10000 threads, same result
@@AntonPutra you'll make me try it on my machine :)
In other tests I've seen online, Rust was better, why is Go ahead here by such a huge margin?
It's only compare both using it's own std library.
because the test is bad. As you can see the rust app reaches at most 15% CPU utilization because of teh very small thread pool he is using
because Rust standard library sucks and people who think this is unfair can't read titles.
@bcassol no it doesn't. It's go stdlib that sucks, ecause in ti.e it will be an outdated unmai tainable mess. A standard library must not contain on essential stuff and stuff that cha ges
because rust does not officially support async library, tokio is the next
please test Encore-ts vs bun elysia framework. Encore team says that they use rust for heavy operation like validation and etc..
yes will do
13 And no man hath ascended up to heaven, but he that came down from heaven, even the Son of man which is in heaven.
14 And as Moses lifted up the serpent in the wilderness, even so must the Son of man be lifted up:
15 That whosoever believeth in him should not perish, but have eternal life.
16 For God so loved the world, that he gave his only begotten Son, that whosoever believeth in him should not perish, but have everlasting life.
17 For God sent not his Son into the world to condemn the world; but that the world through him might be saved.
18 He that believeth on him is not condemned: but he that believeth not is condemned already, because he hath not believed in the name of the only begotten Son of God.
19 And this is the condemnation, that light is come into the world, and men loved darkness rather than light, because their deeds were evil.
20 For every one that doeth evil hateth the light, neither cometh to the light, lest his deeds should be reproved.
21 But he that doeth truth cometh to the light, that his deeds may be made manifest, that they are wrought in God.
(Jn.3:13-21)
.
It would be more interesting when compare rust with zig, everything 😋
This is bad. Extremely bad.
sync library, tokio is next
What the Fak 😲
tokio next
Rust is faster at runtime. But go is faster to develop and compile. It really depends how important each side of the lifecycle is.
For me, i constantly develop and make changes, go has a clear advantage in that respect.
makes sence
Comparing expresso machines with door handles
yes sir
bro did the wrong code comparison 🤦
haha
Could you compare tokio vs rocket rust?
PR to improve Rust - github.com/antonputra/tutorials/pull/422