Why hello world example is slow on first run

Hello Rust Programmers,
Today I started learning Rust, I started with Windows.

I saw hello world took little time on first run (execution) but it is fast on second run. Can I know the reason behind it.

Even all of my program takes little time on first run, then it is executing fast from second run.

Can any one let me know the reason or is my system problem.


Are you executing your program with cargo run?
If so, that command will first compile your code into a binary, and then execute the binary.

For subsequent invocations of the command, there's nothing new to compile and so it runs directly the binary.


No, I am executing like a main.exe

rustc main.rs
main.exe -> This took little time
Again execute
main.exe -> Took no time

1 Like

There shouldn't be anything Rust-specific in this behavior. Rust programs don't have any state that persists across runs. Perhaps it's simply disk cache?


It could also be a virus scanner checking it the first time, and cached for subsequent execution.

1 Like

Thanks I think that could be the issue. I executed on Linux and it works like a charm.

Thanks @cuviper