github.com/koykov/openrt@v0.0.0-20240411200908-3abd933415e1/memmove_test.go (about)

     1  package openrt
     2  
     3  import (
     4  	"testing"
     5  	"unsafe"
     6  )
     7  
     8  type mmove struct {
     9  	a int
    10  	b uint
    11  	c float32
    12  	d uint64
    13  	e float64
    14  	f int16
    15  	g int64
    16  }
    17  
    18  func TestMemmove(t *testing.T) {
    19  	a := mmove{
    20  		a: 1,
    21  		b: 2,
    22  		c: 3,
    23  		d: 4,
    24  		e: 5,
    25  		f: 6,
    26  		g: 7,
    27  	}
    28  	var b mmove
    29  	Memmove(unsafe.Pointer(&b), unsafe.Pointer(&a), unsafe.Sizeof(a))
    30  	if b.d != 4 {
    31  		t.FailNow()
    32  	}
    33  }
    34  
    35  func BenchmarkMemmove(b *testing.B) {
    36  	a := mmove{
    37  		a: 1,
    38  		b: 2,
    39  		c: 3,
    40  		d: 4,
    41  		e: 5,
    42  		f: 6,
    43  		g: 7,
    44  	}
    45  	b.ReportAllocs()
    46  	for i := 0; i < b.N; i++ {
    47  		var b_ mmove
    48  		Memmove(unsafe.Pointer(&b_), unsafe.Pointer(&a), unsafe.Sizeof(a))
    49  	}
    50  }