Created
January 18, 2018 08:33
-
-
Save vnoder/4e69805b9bac6775f61efaafa8892bac to your computer and use it in GitHub Desktop.
fibonacci
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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