package cal import ( "math/big" ) var cache = map[int]*big.Int{} func resetCache() { cache = map[int]*big.Int{} } func Fibonacci(n int) *big.Int { if c := cache[n]; c != nil { return c } ret := new(big.Int) before := big.NewInt(1) for i := 1; i < n; i++ { tmp := new(big.Int).Add(ret, before) before = ret ret = tmp cache[i] = ret } cache[n] = ret return ret } package cal import ( "math/big" "testin
![go testでベンチマークを取ってpprofで時間がかかっている箇所を調べる - sambaiz-net](https://cdn-ak-scissors.b.st-hatena.com/image/square/a9e6dfd6b8e1d1d20651a18da5f07e08d04e3d5e/height=288;version=1;width=512/https%3A%2F%2Fwww.sambaiz.net%2Fimages%2Fmy_l.jpg)