go 斐波那契
3 月,跳不动了?>>> 用go 求解fib比较效率 go可以求解到45项都很快 package main import ( "fmt" "time" ) func Fib(n int) int { if n < 2 { return n } return Fib(n-1) + Fib(n-2) } func single(size int) (int64, []int) { st := time.Now().Unix() ans := make([]int, size) for i := 0; i < size; i++ { ans[i] = Fib(i) } ed := time.Now().Unix() return ed - st, ans } func FibMul(n int, c chan int) { c <- Fib(n) } func Multiple(size int) (int64, []int) { st := time.Now().Unix() ans := make([]int, size) c := make(chan int, size) for i := 0; i < size; i++ { go FibMul(i, c) } for i := 0; i < size; i++ { ans[i] = <-c } ed := time.Now()