github.com/webmafia/fast@v0.10.0/make_test.go (about)

     1  package fast
     2  
     3  import (
     4  	"fmt"
     5  	"testing"
     6  )
     7  
     8  func ExampleMakeNoZero() {
     9  	b := MakeNoZero(16)
    10  	fmt.Printf("Length %d, capacity %d", len(b), cap(b))
    11  	// Output: Length 16, capacity 16
    12  }
    13  
    14  func ExampleMakeNoZeroCap() {
    15  	b := MakeNoZeroCap(0, 16)
    16  	fmt.Printf("Length %d, capacity %d", len(b), cap(b))
    17  	// Output: Length 0, capacity 16
    18  }
    19  
    20  func stdMake(n int) []byte {
    21  	return make([]byte, n)
    22  }
    23  
    24  func BenchmarkMake(b *testing.B) {
    25  	for i := 0; i < b.N; i++ {
    26  		_ = stdMake(256)
    27  	}
    28  }
    29  
    30  func BenchmarkMakeNoZero(b *testing.B) {
    31  	for i := 0; i < b.N; i++ {
    32  		_ = MakeNoZero(256)
    33  	}
    34  }
    35  
    36  func BenchmarkMakeNoZeroCap(b *testing.B) {
    37  	for i := 0; i < b.N; i++ {
    38  		_ = MakeNoZeroCap(0, 256)
    39  	}
    40  }