gitee.com/sy_183/go-common@v1.0.5-0.20231205030221-958cfe129b47/container/linked-map_test.go (about) 1 package container 2 3 import ( 4 "testing" 5 ) 6 7 func BenchmarkLinkedMap(b *testing.B) { 8 b.Run("linked-map", func(b *testing.B) { 9 l := 200000 10 m := NewLinkedMap[int, int](l, l) 11 b.ResetTimer() 12 for i := 0; i < b.N; i++ { 13 for i := 0; i < l; i++ { 14 m.Push(i, i) 15 } 16 var next *LinkedMapEntry[int, int] 17 for first := m.HeadEntry(); first != nil; first = next { 18 next = first.Next() 19 m.RemoveEntry(first) 20 } 21 } 22 }) 23 b.Run("map", func(b *testing.B) { 24 l := 200000 25 m := make(map[int]int, l) 26 b.ResetTimer() 27 for i := 0; i < b.N; i++ { 28 for i := 0; i < l; i++ { 29 m[i] = i 30 } 31 for i := 0; i < l; i++ { 32 delete(m, i) 33 } 34 } 35 }) 36 }