Skip to content

Instantly share code, notes, and snippets.

@azihsoyn
Created December 4, 2016 17:17
Show Gist options
  • Save azihsoyn/6ed8b5bf793bd7e3b0fbcca0e7495f6e to your computer and use it in GitHub Desktop.
Save azihsoyn/6ed8b5bf793bd7e3b0fbcca0e7495f6e to your computer and use it in GitHub Desktop.
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