Created
December 4, 2016 17:17
-
-
Save azihsoyn/6ed8b5bf793bd7e3b0fbcca0e7495f6e 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
package main | |
import ( | |
"reflect" | |
"testing" | |
) | |
func BenchmarkSetIntMap(b *testing.B) { | |
m := make(map[int]bool) | |
for i := 0; i < b.N; i++ { | |
_ = m[i] | |
m[i] = true | |
} | |
} | |
func BenchmarkSetInterfaceMap(b *testing.B) { | |
m := make(map[interface{}]bool) | |
for i := 0; i < b.N; i++ { | |
_ = m[i] | |
m[i] = true | |
} | |
} | |
func BenchmarkSetReflectMap(b *testing.B) { | |
v := 100 | |
t := reflect.ValueOf(false) | |
m := reflect.MakeMap(reflect.MapOf(reflect.ValueOf(v).Type(), t.Type())) | |
b.ResetTimer() | |
for i := 0; i < b.N; i++ { | |
v := reflect.ValueOf(i) | |
_ = m.MapIndex(v) | |
m.SetMapIndex(v, t) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment