Last active
October 21, 2019 07:03
-
-
Save uzilan/f9c254fbf504843e3b763622a255fe2e to your computer and use it in GitHub Desktop.
gosoup
This file contains 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
func GetANumber() int { | |
rand.Seed(time.Now().UnixNano()) // different seed every time | |
return rand.Intn(100) // generate a random number | |
} | |
func BenchmarkGetANumber(b *testing.B) { | |
for i := 0; i < b.N; i++ { | |
GetANumber() | |
} | |
} |
This file contains 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
func Divide(x float32, y float32) (float32, error) { | |
if y == 0 { | |
return 0, errors.New("division by zero") // an error occurred | |
} | |
return x / y, nil // result and no error | |
} | |
func DivisionRunner(x float32, y float32) { | |
result, err := Divide(x, y) | |
if err == nil { | |
fmt.Printf("%v / %v = %v", x, y, result) | |
} else { | |
fmt.Printf("error: %v", err) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment