Home > Article > Backend Development > What is the difference between run and build commands in go language?
Difference: The "go run" command can compile and run the program directly, but it will not generate an exe file, and the running speed is correspondingly slower; the "go build" command is used to test the compiled package, mainly checking whether there is Compilation errors will generate exe files, which run quickly.
The operating environment of this article: windows10 system, Go 1.11.2, thinkpad t480 computer.
Related recommendations: "Go Video Tutorial"
The difference between go run and go build commands
go run:
go run compiles and runs the program directly. It will generate a temporary file (but it does not actually exist and will not generate an .exe file). Directly Output the program execution results on the command line to facilitate user debugging. The running speed is also correspondingly slower
Note: you need to execute go run under the main package, otherwise as shown below
go build:
go build is used to test the compiled package, mainly checking whether there are compilation errors. If it is the source code of an executable file (that is, the main package), an executable file will be generated directly in the current directory ( .exe). Fast running speed
For more programming-related knowledge, please visit:Introduction to Programming! !
The above is the detailed content of What is the difference between run and build commands in go language?. For more information, please follow other related articles on the PHP Chinese website!