Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

os: Go's stdio is too slow #20958

Closed
nilsocket opened this issue Jul 9, 2017 · 1 comment
Closed

os: Go's stdio is too slow #20958

nilsocket opened this issue Jul 9, 2017 · 1 comment

Comments

@nilsocket
Copy link
Contributor

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

go version go1.8.3 linux/amd64

What operating system and processor architecture are you using (go env)?

linux, amd64

What did you do?

A simple for loop,

 package main

 import "fmt"

 func main(){
     for i := 0; i < 1000000; i++ {
         fmt.Println(i)
     }
}

What did you expect to see?

time taken to be around, 1 or 2 seconds

What did you see instead?

time taken is 6 seconds.

I have written the same in python,

for i in range(1,1000000)
    print(i)

time taken for python is around 2.3 seconds.
Since, printing to screen takes time, I have redirected output to files, in both programs.

Another point is, go.txt file is 2 bytes more in size compared to py.txt

Here's the screen shot,

slow_for_loop

@davecheney
Copy link
Contributor

This is not a bug. Go's stdout is not buffered, where pythons is.

We don't the issue tracker to ask questions. Please see https://golang.org/wiki/Questions for good places to ask. Thanks.

@mikioh mikioh changed the title Go's for loop is too slow os: Go's stdio is too slow Jul 10, 2017
@golang golang locked and limited conversation to collaborators Jul 10, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants