Skip to content

Commit

Permalink
chores: fix benchmarks
Browse files Browse the repository at this point in the history
Signed-off-by: m-murad <[email protected]>
  • Loading branch information
m-murad committed Aug 8, 2020
1 parent b7cbcf1 commit e8c6e3c
Showing 1 changed file with 11 additions and 16 deletions.
27 changes: 11 additions & 16 deletions map_benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,20 @@ func populateOrderedSyncMap(m *mp.Map, size int) {
}

func BenchmarkOrderedSyncMapGet(b *testing.B) {
for n := 2; n <= 2048; n *= 2 {
m := initMap()
populateOrderedSyncMap(m, 10)

mapSize := 1000
m := initMap()
populateOrderedSyncMap(m, mapSize)
for n := 1; n <= 10; n++ {
b.Run(fmt.Sprintf("Get form ordered_sync_map - %d", n), func(b *testing.B) {
for i := 0; i < b.N; i++ {
_, _ = m.Get(4)
_, _ = m.Get(b.N % mapSize)
}
})
}
}

func BenchmarkOrderedSyncMapPut(b *testing.B) {
for n := 0; n < 10; n++ {
for n := 1; n <= 10; n++ {
m := mp.New()
b.Run(fmt.Sprintf("Put in ordered_sync_map - %d", n), func(b *testing.B) {
populateOrderedSyncMap(m, b.N)
Expand All @@ -43,10 +43,9 @@ func BenchmarkOrderedSyncMapPut(b *testing.B) {
func BenchmarkOrderedSyncMapDelete(b *testing.B) {
for n := 1; n < 10; n++ {
b.Run(fmt.Sprintf("Delete form ordered_sync_map - %d", n), func(b *testing.B) {
b.StopTimer()
size := b.N
m := getPopulatedOrderedSyncMap(size)
b.StartTimer()
b.ResetTimer()
for i := 0; i < size; i++ {
m.Delete(i)
}
Expand All @@ -57,10 +56,8 @@ func BenchmarkOrderedSyncMapDelete(b *testing.B) {
func BenchmarkOrderedSyncMapUnorderedTraversal(b *testing.B) {
for n := 1; n < 5; n++ {
b.Run(fmt.Sprintf("Traverse ordered_sync_map randomly - %d", n), func(b *testing.B) {
b.StopTimer()
size := b.N
m := getPopulatedOrderedSyncMap(size)
b.StartTimer()
m := getPopulatedOrderedSyncMap(b.N)
b.ResetTimer()
m.UnorderedRange(func(key interface{}, value interface{}) {})
})
}
Expand All @@ -69,10 +66,8 @@ func BenchmarkOrderedSyncMapUnorderedTraversal(b *testing.B) {
func BenchmarkOrderedSyncMapOrderedTraversal(b *testing.B) {
for n := 1; n < 5; n++ {
b.Run(fmt.Sprintf("Traverse ordered_sync_map in order - %d", n), func(b *testing.B) {
b.StopTimer()
size := b.N
m := getPopulatedOrderedSyncMap(size)
b.StartTimer()
m := getPopulatedOrderedSyncMap(b.N)
b.ResetTimer()
m.OrderedRange(func(key interface{}, value interface{}) {})
})
}
Expand Down

0 comments on commit e8c6e3c

Please sign in to comment.