github.com/parquet-go/parquet-go@v0.21.1-0.20240501160520-b3c3a0c3ed6f/internal/bytealg/broadcast_test.go (about) 1 package bytealg_test 2 3 import ( 4 "fmt" 5 "testing" 6 7 "github.com/parquet-go/parquet-go/internal/bytealg" 8 ) 9 10 func TestBroadcast(t *testing.T) { 11 const N = 100_0000 12 buffer := make([]byte, N) 13 14 for n := 1; n <= N; n = (n * 2) + 1 { 15 t.Run(fmt.Sprintf("size=%d", n), func(t *testing.T) { 16 b := buffer[:n] 17 18 for i := range b { 19 b[i] = 0 20 } 21 22 bytealg.Broadcast(b, 42) 23 24 for i, c := range b { 25 if c != 42 { 26 t.Fatalf("byte at index %d has value %d", i, c) 27 } 28 } 29 }) 30 } 31 } 32 33 func BenchmarkBroadcast(b *testing.B) { 34 for _, size := range []int{0, 10, 100, 1000, 10_000} { 35 b.Run(fmt.Sprintf("size=%d", size), func(b *testing.B) { 36 data := make([]byte, size) 37 38 for i := 0; i < b.N; i++ { 39 bytealg.Broadcast(data, 1) 40 } 41 42 b.SetBytes(int64(size)) 43 }) 44 } 45 }