Skip to content

Instantly share code, notes, and snippets.

@vnoder
Created January 18, 2018 08:33
Show Gist options
  • Save vnoder/4e69805b9bac6775f61efaafa8892bac to your computer and use it in GitHub Desktop.
Save vnoder/4e69805b9bac6775f61efaafa8892bac to your computer and use it in GitHub Desktop.
fibonacci
package main
import (
"fmt"
"time"
"runtime"
)
func fibonacci(num int) int {
if num < 2 {
return 1
}
return fibonacci(num-1) + fibonacci(num-2)
}
func main() {
ch := make(chan int, 8)
runtime.GOMAXPROCS(8)
start := time.Now()
for i := 0; i < 8; i++ {
go func() {
nums := fibonacci(20)
ch <- nums
}()
}
for i := 0; i < 8; i++ {
fmt.Println(<-ch)
}
fmt.Println("total time:", time.Since(start))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment