Skip to content

Instantly share code, notes, and snippets.

@gloriousCode
Created June 23, 2020 22:21
Show Gist options
  • Save gloriousCode/e29c5adf458170fd09c22c3503913bf0 to your computer and use it in GitHub Desktop.
Save gloriousCode/e29c5adf458170fd09c22c3503913bf0 to your computer and use it in GitHub Desktop.
var letters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
func randSeq(n int) string {
b := make([]rune, n)
for i := range b {
b[i] = letters[rand.Intn(len(letters))]
}
return string(b)
}
var lim = 4
func BenchmarkFor(b *testing.B) {
rand.Seed(time.Now().UnixNano())
mapperino := make(map[string][]string)
for i := 0; i < lim; i++ {
var ranString = randSeq(10)
mapperino[ranString] = []string{ranString}
}
var output string
b.ResetTimer()
for i := 0; i < b.N; i++ {
for j := range mapperino {
output = j + mapperino[j][0]
}
}
b.Log(output)
}
func BenchmarkForExtra(b *testing.B) {
rand.Seed(time.Now().UnixNano())
mapperino := make(map[string][]string)
for i := 0; i < lim; i++ {
var ranString = randSeq(10)
mapperino[ranString] = []string{ranString}
}
var output string
b.ResetTimer()
for i := 0; i < b.N; i++ {
for k, v := range mapperino {
output = k + v[0]
}
}
b.Log(output)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment