gitee.com/sy_183/go-common@v1.0.5-0.20231205030221-958cfe129b47/container/tree-map_test.go (about) 1 package container 2 3 import ( 4 "fmt" 5 "testing" 6 ) 7 8 func TestTreeMap(t *testing.T) { 9 l := 200000 10 m := NewOrderedTreeMap[int, int](l) 11 for i := 0; i < l; i++ { 12 m.Put(i, i) 13 } 14 //var next *TreeMapEntry[int, int] 15 //for first := m.HeadEntry(); first != nil; first = next { 16 // next = first.Next() 17 // m.RemoveEntry(first) 18 //} 19 m.Clear() 20 fmt.Println(m.Len()) 21 } 22 23 func BenchmarkTreeMap(b *testing.B) { 24 b.Run("tree-map", func(b *testing.B) { 25 l := 200000 26 m := NewOrderedKeyTreeMap[int, int](l) 27 b.ResetTimer() 28 for i := 0; i < 100; i++ { 29 for i := 0; i < l; i++ { 30 m.Put(i, i) 31 } 32 m.Clear() 33 //var next *TreeMapEntry[int, int] 34 //for first := m.HeadEntry(); first != nil; first = next { 35 // next = first.Next() 36 // m.RemoveEntry(first) 37 //} 38 } 39 }) 40 b.Run("map", func(b *testing.B) { 41 l := 200000 42 m := make(map[int]int, l) 43 b.ResetTimer() 44 for i := 0; i < b.N; i++ { 45 for i := 0; i < l; i++ { 46 m[i] = i 47 } 48 for i := 0; i < l; i++ { 49 delete(m, i) 50 } 51 } 52 }) 53 }