Go run for hello world program takes a long time

Hi,

I followed the steps here after I installed Go. However, running go run hello.go takes around 20 seconds for it to output “hello, world”. I’ve also tried reinstalling and excluding my Go folder from windows defender (the only antivirus I use). How do I fix this? Any help is appreciated.

Specs:

  • windows 10
  • intel i7-6700

Thanks!

No.

go run does not run the executable from where you are, it instead compiles to a temporary location and runs the executable in that location.

Try go build instead and run the executable that has been created right in your current folder.

1 Like

Well executing isn’t the issue (it works fine), the problem is the long compile time. I really don’t think a simple hello world program would take more than 10 seconds to compile.

Is go build as well taking as long as go run?

As I said, I still have the virus scanner under suspicion.

Yes.

How would I configure Windows Defender then?

According to https://stackoverflow.com/questions/46570517/where-is-executable-stored-after-go-run-file-go-command, the executable is stored in %TEMP%. Ignoring this in your virus scanner is probably a massive isssue and I would advise against it.

I do assume that intermediate files are created there as well.

I currently do not see a way to solve your problem without disabling the antivirus.

1 Like

Ignoring the temp folder doesn’t help. I’ve also installed Go on my laptop which is also windows 10, using windows defender and I have the same exact issue. Could this be a bug?

What am I supposed to do with this information?

Do you have the same problem when you temporarily disable the virus scanner?

Yes, I have the same problem when I turn real time protection off. I’ve confirmed that it has no effect on the compile time.

Did you install the 32 or 64 bits version of the Go compiler?

My go version is go1.13.6 windows/amd64

I’ve changed the Go temp directory to somewhere else (as opposed to excluding %TEMP%) so it got excluded from Windows defender, which significantly improved compile time.

PS C:\go\src\hello> Measure-Command {go run hello.go}


Days              : 0
Hours             : 0
Minutes           : 0
Seconds           : 7
Milliseconds      : 663
Ticks             : 76633164
TotalDays         : 8.86957916666667E-05
TotalHours        : 0.002128699
TotalMinutes      : 0.12772194
TotalSeconds      : 7.6633164
TotalMilliseconds : 7663.3164

Current run time, compared to 3 seconds from @rot13

Do yourself a favor, and do your Go development in Linux.

I have a Windows 10 laptop. I installed Virtualbox, and then created a Linux VM where I do Go work.

Super nice, you get the Linux GUI and everything.

Instructions here:

https://www.dbdr.com/build-a-linux-vm-for-working-with-go/

Good luck.

Jeff Kayser

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.