gitee.com/quant1x/num@v0.3.2/binary/memory_test.go (about) 1 package binary 2 3 import ( 4 "fmt" 5 "testing" 6 "unsafe" 7 ) 8 9 func TestMemory(t *testing.T) { 10 x := 1.1 11 p1 := uintptr(unsafe.Pointer(&x)) 12 fmt.Printf("x = %p, p1 = %d\n", &x, p1) 13 m := MemData(x) 14 fmt.Printf("p1: %p\n", m.address()) 15 fmt.Println(m) 16 b := m.Bytes() 17 fmt.Printf("p2: %p, float64=%f\n", b, m.Float64()) 18 } 19 20 func BenchmarkMemData(b *testing.B) { 21 for i := 0; i < b.N; i++ { 22 x := 1.1 23 m := MemData(x) 24 b := m.Bytes() 25 _ = b 26 } 27 }