初级会员
  • 第 13683 位会员
  • coderAndExperience
  • 2017-10-26 07:35:48
  • Offline
  • 20 20

最近发布的主题

    暂无

最近发布的文章

    暂无

最近分享的资源

    暂无

最近发布的项目

    暂无

最近的评论

  • 没发现有这么慢 package main import( "fmt" "time" "math" ) func main() { fmt.Println("total time: ", time.Now().String()) sum := 0 t1 := time.Now() for i :=0; i <= 10000000; i++ { if isPrime(i) == true { sum += 1 } } fmt.Println("total prime numbers: ", sum) fmt.Println("total time: ", time.Now().String()) fmt.Println(time.Now().Sub(t1)) } func isPrime(n int) bool { end := int(math.Sqrt(float64(n))) for i := 2; i <= end; i++ { if n%i == 0 { return false } } return true } 结果: D:\go-project-space>test.exe total time: 2017-10-26 15:34:18.329 +0800 CST m=+0.006000000 total prime numbers: 664581 total time: 2017-10-26 15:34:36.355 +0800 CST m=+18.032000000 18.013s D:\go-project-space>test.exe total time: 2017-10-26 15:39:11.322 +0800 CST m=+0.005000000 total prime numbers: 664581 total time: 2017-10-26 15:39:29.511 +0800 CST m=+18.194000000 18.171s 版本 go version go1.9.1 windows/amd64