package main import ( "fmt" "math" "sync" ) func CreateSqrtMap() map[int]float64 { numKeys := 100_000 newMap := make(map[int]float64) for i := range numKeys { newMap[i] = math.Sqrt(float64(i)) } return newMap } var initCreateMapSqrt func() map[int]float64 = sync.OnceValue(CreateSqrtMap) func main() { sqrtMap := initCreateMapSqrt() n := 100_000 / 1_000 for i := range n { keyVal := i * 1_000 fmt.Printf("Value of map by key[%d]: %f\n", keyVal, sqrtMap[keyVal]) } }