github.com/moontrade/unsafe@v0.9.1/memory/tlsf/mem_test.go (about)

     1  package tlsf
     2  
     3  import (
     4  	"testing"
     5  	"unsafe"
     6  )
     7  
     8  func BenchmarkMemzero(b *testing.B) {
     9  	buf := make([]byte, 16)
    10  	buf[0] = 77
    11  	buf[15] = 88
    12  
    13  	Zero(unsafe.Pointer(&buf[0]), uintptr(len(buf)))
    14  
    15  	ptr := unsafe.Pointer(&buf[0])
    16  
    17  	b.Run("memclr", func(b *testing.B) {
    18  		for i := 0; i < b.N; i++ {
    19  			Zero(ptr, uintptr(len(buf)))
    20  		}
    21  	})
    22  
    23  	b.Run("slow", func(b *testing.B) {
    24  		for i := 0; i < b.N; i++ {
    25  			zeroSlow(ptr, uintptr(len(buf)))
    26  		}
    27  	})
    28  }