Created
February 27, 2020 19:04
-
-
Save tmountain/ffd5f14339aa50548009ddec3673f03f to your computer and use it in GitHub Desktop.
Testing Golang's ability to saturate cores
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" | |
) | |
func fibonacci(n uint) uint64 { | |
if n <= 1 { | |
return uint64(n) | |
} | |
var n2, n1 uint64 = 0, 1 | |
for i := uint(2); i < n; i++ { | |
n2, n1 = n1, n1+n2 | |
} | |
return n2 + n1 | |
} | |
func runFib(max uint, c chan uint64) { | |
c <- fibonacci(max) | |
} | |
func main() { | |
ch := make(chan uint64) | |
for i := 0; i < 10; i++ { | |
go runFib(10000000000, ch) | |
} | |
for v := range ch { | |
fmt.Printf("%v\n", v) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment