Go run for hello world program takes a long time


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.


  • windows 10
  • intel i7-6700


Does rerunning the command result in fewer seconds for output?


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

Running grep.exe -r hello "$APPDATA/go-build" returns a result for a binary file,
and running the file.exe command on that file returns current ar archive.

SFU/SUA Interix was deprecated circa Windows 8.0.


Welcome to the Interix UNIX utilities.

$ time /dev/fs/C/Programmer/go/bin/go.exe run go/src/hello/hello.go
hello, world
    2.26s real     0.53s user     0.28s system

Here’s 9pm’s time.exe running on Windows XP Home. (9pm)


% time.exe /Programmer/go/bin/go.exe run hello.go
hello, world
0.438u 0.359s 2.125r 	 /Programmer/go/bin/go.exe run hello.go

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.


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
$ ls.exe -R /tmp/go-build*


exe  importcfg.link



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?

Git for Windows (legacy)


time is a shell built-in

$ uname.exe -ms
MINGW32_NT-5.1 i686

$ echo.exe $SHELL

$ which.exe time.exe
which: no time.exe in (/usr/bin:/C/WINDOWS/system32:/C/WINDOWS:/C/WINDOWS/System32/Wbem:/C/Programmer/go/bin)

$ time go.exe run hello.go
hello, world

real    0m3.703s
user    0m0.015s
sys     0m0.046s

$ ps.exe x
      PID    PPID    PGID     WINPID   TTY         UID    STIME COMMAND
     2160       1    2160       2160  cons0     197613 18:33:43 /usr/bin/bash
     2264    2160    2264       2620  cons0     197613 18:33:51 /usr/bin/ps

$ rm.exe -r "$APPDATA/go-build"


time is a shell built-in

% uname.exe -ms
MSYS_NT-5.1 i686
% echo.exe $SHELL
% which.exe time.exe
which: no time.exe in (/usr/bin:/C/WINDOWS/system32:/C/WINDOWS:/C/WINDOWS/System32/Wbem:/C/Programmer/go/bin)
% time go.exe run go/src/hello/hello.go
hello, world
0.031u 0.015s 0:04.15 0.9%      0+0k 0+0io 1057pf+0w
% ps.exe x
      PID    PPID    PGID     WINPID   TTY         UID    STIME COMMAND
     3732    2576    3732       2208  pty0      197613 18:31:13 /usr/bin/ps
     2576    1536    2576       2712  pty0      197613 18:18:15 /usr/bin/tcsh
     1536       1    1536       1536  ?         197613 18:18:15 /usr/bin/mintty

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 @nurmi-labs

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:


Good luck.

Jeff Kayser


go1.13.6 (Linux / 386)

bash-4.3$ uname -mp                             
i686 Intel(R) Atom(TM) CPU N270   @ 1.60GHz
bash-4.3$ free --giga | perl -lae 'print @F[0,1] if $. == 2'
bash-4.3$ export PATH=/usr/local/go/bin:${PATH}
bash-4.3$ mkdir -p ~/go/src/hello
bash-4.3$ cat << EOF | gofmt > ~/go/src/hello/hello.go
> package main
> import "fmt"
> func main() {
> fmt.Printf("hello, world\n")
> }
bash-4.3$ /usr/bin/time -p go run ~/go/src/hello/hello.go
hello, world
real 2.33
user 1.59
sys 0.31
bash-4.3$ rm -r ~/.cache/go-build
bash-4.3$ $PLAN9/bin/time go run ~/go/src/hello/hello.go
hello, world
1.57u 0.35s 1.86r 	 go run /home/eric/go/src/hello/hello.go
bash-4.3$ file /usr/local/go/bin/go
/usr/local/go/bin/go: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux.so.2, Go BuildID=bVwMwAdXBpYp4PBvIrqZ/vbfX15UF6cgq3THigMUx/QSxQRVWmK-8uFUlegS1A/TD0XQ0eQXwJkvrDVR_B1, not stripped
bash-4.3$ rm -r ~/.cache/go-build

Stripping the files from go1.13.6.linux-386.tar.gz the time is slightly different.

GNU 1.7
real 2.23
user 1.49
sys 0.36

Plan 9 from User Space
1.58u 0.31s 1.81r

go1.13.6 (Plan 9 / 386)

% go version
go version go1.13.6 plan9/386
% time go run hello.go
hello, world
0.04u 0.25s 0.77r 	 go run hello.go

go1.13.7 (macOS) Dual-Core Intel Core i5 2.6 GHz

$time go run hello.go
hello, world

real   0m1.410s
user   0m0.306s
sys    0m0.377s