github.com/egonelbre/exp@v0.0.0-20240430123955-ed1d3aa93911/reflectmap/all_test.go (about) 1 package reflectmap 2 3 import ( 4 "testing" 5 "unsafe" 6 ) 7 8 func TestReflect(t *testing.T) { 9 m := NewMap(0, 0) 10 m.Add(56, 12) 11 } 12 13 func TestReflectPointer(t *testing.T) { 14 m := NewPointerMap(0, 0) 15 x, y := 56, 12 16 m.Add(unsafe.Pointer(&x), unsafe.Pointer(&y)) 17 } 18 19 func TestUnsafe(t *testing.T) { 20 m := NewUnsafeMap(0, 0) 21 m.Add(56, 12) 22 } 23 24 func BenchmarkReflect(b *testing.B) { 25 m := NewMap(0, 0) 26 for i := 0; i < b.N; i++ { 27 m.Add(i, i) 28 } 29 } 30 31 func BenchmarkReflectPointer(b *testing.B) { 32 m := NewPointerMap(0, 0) 33 for i := 0; i < b.N; i++ { 34 m.Add(unsafe.Pointer(&i), unsafe.Pointer(&i)) 35 } 36 } 37 func BenchmarkUnsafe(b *testing.B) { 38 m := NewUnsafeMap(0, 0) 39 for i := 0; i < b.N; i++ { 40 m.Add(i, i) 41 } 42 } 43 func BenchmarkSpecial(b *testing.B) { 44 m := NewSpecialMap() 45 for i := 0; i < b.N; i++ { 46 m.Add(i, i) 47 } 48 }