github.com/go-eden/common@v0.1.15-0.20210617133546-059099253264/esync/sync_atomic_pointer_test.go (about) 1 package esync 2 3 import ( 4 "github.com/stretchr/testify/assert" 5 "testing" 6 ) 7 8 func TestAtomicPointer(t *testing.T) { 9 var p AtomicPointer 10 11 assert.True(t, p.Get() == nil) 12 13 s1 := []byte("hello") 14 p.Set(s1) 15 t.Log(p.Get()) 16 } 17 18 // BenchmarkAtomicPointer_Set-12 18869185 55.95 ns/op 40 B/op 2 allocs/op 19 func BenchmarkAtomicPointer_Set(b *testing.B) { 20 var p AtomicPointer 21 s1 := []byte("hello") 22 b.ResetTimer() 23 b.ReportAllocs() 24 for i := 0; i < b.N; i++ { 25 p.Set(s1) 26 } 27 } 28 29 // BenchmarkAtomicPointer_Get-12 797969247 1.398 ns/op 0 B/op 0 allocs/op 30 func BenchmarkAtomicPointer_Get(b *testing.B) { 31 var p AtomicPointer 32 p.Set([]byte("hello")) 33 b.ResetTimer() 34 b.ReportAllocs() 35 for i := 0; i < b.N; i++ { 36 _ = p.Get().([]byte) 37 } 38 }