Forked from romanitalian/2020_who_is_faster_golang.sh
Last active
December 15, 2020 20:38
-
-
Save mwf/02b9c3b16b92704893de0447005aa3d8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"math" | |
"time" | |
) | |
func isPrime(num int32) bool { | |
if num == 2 { | |
return true | |
} | |
if num == 1 || num%2 == 0 { | |
return false | |
} | |
to := int32(math.Sqrt(float64(num))) | |
for div := int32(3); div <= to; div += 2 { | |
if num%div == 0 { | |
return false | |
} | |
} | |
return true | |
} | |
func do(N int32) { | |
for i := int32(0); i < N; i++ { | |
prime := isPrime(i) | |
if prime { | |
// fmt.Printf("%+v: %+v\n", i, prime) | |
} | |
} | |
} | |
func main() { | |
st := time.Now() | |
do(10_000_000) | |
fmt.Printf("%+v\n", time.Since(st)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment