How to make my program faster?

I just started learning rust yesterday and I want to know if there is any way I can speed up
this program ?

We prefer markdown to images on this forum:

code goes here

And you should see it in the preview pane like

use std::io::{Write, Read};
fn main() {
   println!("etc, etc");

First things first: Did you build/run your code with --release?


I can't think of anything that would make the program particularly faster. Network time is going to dominate anything specific to your code. If you're going to be making multiple requests, and especially multiple concurrent requests, you're probably going to want a client library that implements connection pools, async, and keep-alive, like reqwest. Or if you don't need async, perhaps ureq.


Make sure you add --release flag when you build or run it. The default is to run in debug mode which can be 50 times slower.

read_to_string reads everything it can, so it has to wait until the connection is closed. This will make your program wait for the other side to disconnect. Network protocols usually specify a length of bytes to read or some terminator character to read a fixed number of bytes without waiting for disconnection. You will need to design your network protocol and change the sending side, or use an existing protocol like HTTP.

yup I thought I had compiled it with --release but I guess I didn't now that i've compiled it with release it's way faster.