Last active
August 2, 2017 18:54
-
-
Save apiarian/66daaa1ef8fffff945783c1243051fb8 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/* | |
go test -bench Map -run Map -benchmem -benchtime 10s | |
BenchmarkMapNestedPopulate-4 50000000 493 ns/op 72 B/op 1 allocs/op | |
BenchmarkMapNestedQuery-4 50000000 336 ns/op 1 B/op 1 allocs/op | |
BenchmarkMapCompoundPopulate-4 30000000 723 ns/op 209 B/op 0 allocs/op | |
BenchmarkMapCompoundQuery-4 50000000 387 ns/op 0 B/op 0 allocs/op | |
*/ | |
func BenchmarkMapNestedPopulate(b *testing.B) { | |
m := make(map[string]map[int64]int64) | |
const tpCount = 20 | |
const topic = "some-topic" | |
for i := 0; i < tpCount; i++ { | |
m[topic+":"+strconv.Itoa(i)] = make(map[int64]int64) | |
} | |
b.ResetTimer() | |
for i := 0; i < b.N; i++ { | |
m[topic+":"+strconv.Itoa(i%tpCount)][int64(i)] = int64(i * 2) | |
} | |
} | |
func BenchmarkMapNestedQuery(b *testing.B) { | |
m := make(map[string]map[int64]int64) | |
const tpCount = 20 | |
const topic = "some-topic" | |
for i := 0; i < tpCount; i++ { | |
m[topic+":"+strconv.Itoa(i)] = make(map[int64]int64) | |
} | |
for i := 0; i < b.N; i++ { | |
m[topic+":"+strconv.Itoa(i%tpCount)][int64(i)] = int64(i * 2) | |
} | |
b.ResetTimer() | |
for i := 0; i < b.N; i++ { | |
m[topic+":"+strconv.Itoa(i%tpCount)][int64(i)]++ | |
} | |
} | |
func BenchmarkMapCompoundPopulate(b *testing.B) { | |
type key struct { | |
topic string | |
partition int32 | |
offset int64 | |
} | |
const tpCount = 20 | |
const topic = "some-topic" | |
m := make(map[key]int64) | |
b.ResetTimer() | |
for i := 0; i < b.N; i++ { | |
m[key{topic, int32(i % tpCount), int64(i)}] = int64(i * 2) | |
} | |
} | |
func BenchmarkMapCompoundQuery(b *testing.B) { | |
type key struct { | |
topic string | |
partition int32 | |
offset int64 | |
} | |
const tpCount = 20 | |
const topic = "some-topic" | |
m := make(map[key]int64) | |
for i := 0; i < b.N; i++ { | |
m[key{topic, int32(i % tpCount), int64(i)}] = int64(i * 2) | |
} | |
b.ResetTimer() | |
for i := 0; i < b.N; i++ { | |
m[key{topic, int32(i % tpCount), int64(i)}]++ | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment