diff --git a/main.go b/main.go index 2d46a7e..73eccf9 100644 --- a/main.go +++ b/main.go @@ -7,6 +7,7 @@ import ( "fmt" "log" "os" + "runtime" "strconv" "time" ) @@ -52,12 +53,18 @@ func checkIsDivisibleByPrime(number, offset, stride int, primes *[]int, resultCh func generatePrimes(upperLimit int, loadList bool) []int { var primes []int + bootTime := time.Now() + if loadList { primes = loadPrimes() } else { primes = []int{2, 3, 5} } + numRoutines := runtime.NumCPU() + + fmt.Printf("Startup time: %v\nCalculating with %d routines\n\n", time.Now().Sub(bootTime), numRoutines) + progress := make(chan float32) go printProgress(progress, "Generating primes") @@ -73,7 +80,6 @@ func generatePrimes(upperLimit int, loadList bool) []int { checkCtx, checkCancel := context.WithCancel(context.Background()) resultChannel := make(chan bool) - numRoutines := 12 for r := 0; r < numRoutines; r++ { go checkIsDivisibleByPrime(i, r, numRoutines, &primes, resultChannel, checkCtx)