Skip to content

Instantly share code, notes, and snippets.

@178inaba
Created September 23, 2016 15:34
Show Gist options
  • Save 178inaba/42e233cf5bc44d4907e90fe0c194da48 to your computer and use it in GitHub Desktop.
Save 178inaba/42e233cf5bc44d4907e90fe0c194da48 to your computer and use it in GitHub Desktop.
Trial golang benchmark.
package division
// Division is ...
func Division(n float64) float64 {
return n / 10
}
// Multiplication is ...
func Multiplication(n float64) float64 {
return n * 0.1
}
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