Println!() vs write!() + std::io::stdout().lock()

⚓ Rust    📅 2025-05-01    👤 surdeus    👁️ 5      

surdeus

Warning

This post was published 112 days ago. The information described in this article may have changed.

Context: figuring out the less-than-obvious parts of std.


Getting some mixed results from the use of println!(...) macro vs manual locking of the std::io::stdout() before calling the write!(...) on the lock() of the Stdout itself.

Sample code is here.

Question: how come the playground's execution is on the order of a few ms - regardless of whether it's a Debug or Release mode, while on my own local Win10 the println!() easily takes around 100+ ms, with the write!() into the StdoutLock<'_> is taking 1.25x to 1.5x+ as much?

That last bit is particularly surprising. Shouldn't println!() always be slower?

from my terminal (click for more details)

1 post - 1 participant

Read full topic

🏷️ rust_feed