Created
March 5, 2015 17:19
-
-
Save ttacon/6cbaef09962b70de4e82 to your computer and use it in GitHub Desktop.
Go: map[string]interface{} vs map[string]string
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 mem | |
import "testing" | |
// So if you're encoding small types (i.e. for JSON on the fly) there is a difference. | |
// | |
// maptypes$ go test -bench=. -benchtime=20s | |
// testing: warning: no tests to run | |
// PASS | |
// Benchmark_MapStringInterface 20000000 1407 ns/op 352 B/op 3 allocs/op | |
// Benchmark_MapStringString 20000000 1130 ns/op 336 B/op 2 allocs/op | |
// ok test/mem/maptypes 54.116s | |
// | |
func Benchmark_MapStringInterface(b *testing.B) { | |
b.ReportAllocs() | |
b.ResetTimer() | |
for i := 0; i < b.N; i++ { | |
_ = map[string]interface{}{ | |
"hello": "foo", | |
} | |
} | |
} | |
func Benchmark_MapStringString(b *testing.B) { | |
b.ReportAllocs() | |
b.ResetTimer() | |
for i := 0; i < b.N; i++ { | |
_ = map[string]string{ | |
"hello": "foo", | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment