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

     1  package openrt
     2  
     3  import (
     4  	"math"
     5  	"testing"
     6  	"unsafe"
     7  )
     8  
     9  const meqMB = 1024 * 1024
    10  
    11  var meqA, meqB []byte
    12  
    13  func init() {
    14  	meqA, meqB = make([]byte, meqMB), make([]byte, meqMB)
    15  	for i := 0; i < meqMB; i++ {
    16  		meqA[i], meqB[i] = byte(i%math.MaxUint8), byte(i%math.MaxUint8)
    17  	}
    18  }
    19  
    20  func TestMemequal(t *testing.T) {
    21  	if !Memequal(unsafe.Pointer(&meqA[0]), unsafe.Pointer(&meqB[0]), meqMB) {
    22  		t.FailNow()
    23  	}
    24  }
    25  
    26  func BenchmarkMemequal(b *testing.B) {
    27  	b.ReportAllocs()
    28  	for i := 0; i < b.N; i++ {
    29  		Memequal(unsafe.Pointer(&meqA[0]), unsafe.Pointer(&meqB[0]), meqMB)
    30  	}
    31  }