Why is Rust println! slower than Java println?
Every now and then I come accross a post where Rust is slower than other languages and the root cause turns out to be that println! is slow. However, I haven't seen a satisfying explanation of why Rust's println! is slower.
To make the question more well formed, I did a simple benchmark. I benchmarked the following programs: https://gist.github.com/FeldrinH/83b73b86a05ca593852791bdc4b3471c, and the Rust program took \5.2 s whereas the Java program took \2.8 s. A pretty significant difference.
What I am curious about is what makes Rust's println! implementation so much slower, and more importantly why was it designed this way? For example why doesn't Rust just use the same optimizations as Java, whatever they may be?
EDIT: Yes the Rust version was measured with cargo run --release.
EDIT: The question isn't about how to write to stdout fast in Rust, the question is about what makes Java's println faster and why doesn't Rust use the same optimizations.