Created
June 23, 2020 22:21
-
-
Save gloriousCode/e29c5adf458170fd09c22c3503913bf0 to your computer and use it in GitHub Desktop.
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
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