Skip to main content

Write Program

Write

In Go, Sieve of Eratosthenes can be written as

go/src/prime.go
loading...

Build for Test

Build Go program to executable file.
This command generates main.exe.

build with go
go build -tags=release -ldflags="-s -w" src/main.go src/prime.go

Here, -tags=release and -ldflags are for optimizing.
Go command line options can be found at here.

Run and Test

Now, run the executable file.
And, invoke and test the function.

invoke main function
main.exe 100000
output
given number = 100000
max prime = 99991
duration [ns] = 63042700

Or, go command can directly invoke the program and results in same output.

directly invoke main function
go run -tags=release -ldflags="-s -w" src/main.go src/prime.go 100000

The following table shows the calculated prime for given "N".

given Nprime
22
33
107
10097
1000997
100009973
10000099991