github.com/sixexorg/magnetic-ring@v0.0.0-20191119090307-31705a21e419/common/sink/zero_copy_source_test.go (about)

     1  package sink
     2  
     3  import (
     4  	"crypto/rand"
     5  	"testing"
     6  )
     7  
     8  func BenchmarkZeroCopySource(b *testing.B) {
     9  	const N = 12000
    10  	buf := make([]byte, N)
    11  	rand.Read(buf)
    12  
    13  	for i := 0; i < b.N; i++ {
    14  		source := NewZeroCopySource(buf)
    15  		for j := 0; j < N/100; j++ {
    16  			source.NextUint16()
    17  			source.NextByte()
    18  			source.NextUint64()
    19  			source.NextVarUint()
    20  			source.NextBytes(20)
    21  		}
    22  	}
    23  
    24  }