Skip to content

Instantly share code, notes, and snippets.

@tmountain
Created February 27, 2020 19:04
Show Gist options
  • Save tmountain/ffd5f14339aa50548009ddec3673f03f to your computer and use it in GitHub Desktop.
Save tmountain/ffd5f14339aa50548009ddec3673f03f to your computer and use it in GitHub Desktop.
Testing Golang's ability to saturate cores
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