Created
September 23, 2016 15:34
-
-
Save 178inaba/42e233cf5bc44d4907e90fe0c194da48 to your computer and use it in GitHub Desktop.
Trial golang benchmark.
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 division | |
// Division is ... | |
func Division(n float64) float64 { | |
return n / 10 | |
} | |
// Multiplication is ... | |
func Multiplication(n float64) float64 { | |
return n * 0.1 | |
} |
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 division | |
import ( | |
"math/rand" | |
"os" | |
"testing" | |
"time" | |
) | |
var values []float64 | |
func TestMain(m *testing.M) { | |
rand.Seed(time.Now().UnixNano()) | |
for i := 0; i < 1000000; i++ { | |
values = append(values, float64(rand.Int63n(10000)*10)) | |
} | |
os.Exit(m.Run()) | |
} | |
func BenchmarkDivision(b *testing.B) { | |
for i := 0; i < b.N; i++ { | |
b.Log(Division(values[i])) | |
} | |
} | |
func BenchmarkMultiplication(b *testing.B) { | |
for i := 0; i < b.N; i++ { | |
b.Log(Multiplication(values[i])) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment