DEV Community

manuel
manuel

Posted on • Originally published at mnlwldr.com on

3 3

println() and fmt.Println()

#go

println() is a built-in function and looks useful to developers, because they lack dependencies. But there is a difference between fmt.Println() and println().

println() write to stderr instead of stdout and I never noticed that before, maybe because I didn’t used println so much in the past.

I discovered this because I wanted to compare the throughput of

for {
    fmt.Println("y")
}
Enter fullscreen mode Exit fullscreen mode

and

for {    
    println("y")    
}        
Enter fullscreen mode Exit fullscreen mode

by pipe this to pv -r. So I wondered why I got a lot of “y” in the println() variant.

The println built-in function formats its arguments in an implementation-specific way and writes the result to standard error. Spaces are always added between arguments and a newline is appended. Println is useful for bootstrapping and debugging; it is not guaranteed to stay in the language.

println in the Golang built-in documentation

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (0)

AWS GenAI LIVE image

Real challenges. Real solutions. Real talk.

From technical discussions to philosophical debates, AWS and AWS Partners examine the impact and evolution of gen AI.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay