Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "fmt"
- "math"
- "time"
- )
- var list = make([]int, 0, 1)
- func checkPrime(numero int) {
- var lim = (int)(math.Floor(math.Sqrt(float64(numero))) + 1)
- for j := 0; j < len(list); j++ {
- if numero%list[j] == 0 {
- return
- }
- if list[j] > lim {
- break
- }
- }
- list = append(list,numero)
- }
- func getPrimes(upperLimit int) {
- for i := 3; i < upperLimit; i += 2 {
- checkPrime(i)
- }
- }
- func main() {
- benchmakFunction(func() {
- getPrimes(67108864)
- })
- fmt.Println(len(list),list[len(list)-1])
- }
- func benchmakFunction(functionToBench func()) {
- list = append(list,2)
- fmt.Println(time.Now())
- functionToBench()
- fmt.Println(time.Now())
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement