github.com/go-asm/go@v1.21.1-0.20240213172139-40c5ead50c48/cmd/compile/test/issue53888_test.go (about) 1 // Copyright 2022 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 //go:build !race 6 7 package test 8 9 import ( 10 "testing" 11 12 "github.com/go-asm/go/testenv" 13 ) 14 15 func TestAppendOfMake(t *testing.T) { 16 testenv.SkipIfOptimizationOff(t) 17 for n := 32; n < 33; n++ { // avoid stack allocation of make() 18 b := make([]byte, n) 19 f := func() { 20 b = append(b[:0], make([]byte, n)...) 21 } 22 if n := testing.AllocsPerRun(10, f); n > 0 { 23 t.Errorf("got %f allocs, want 0", n) 24 } 25 type S []byte 26 27 s := make(S, n) 28 g := func() { 29 s = append(s[:0], make(S, n)...) 30 } 31 if n := testing.AllocsPerRun(10, g); n > 0 { 32 t.Errorf("got %f allocs, want 0", n) 33 } 34 h := func() { 35 s = append(s[:0], make([]byte, n)...) 36 } 37 if n := testing.AllocsPerRun(10, h); n > 0 { 38 t.Errorf("got %f allocs, want 0", n) 39 } 40 i := func() { 41 b = append(b[:0], make(S, n)...) 42 } 43 if n := testing.AllocsPerRun(10, i); n > 0 { 44 t.Errorf("got %f allocs, want 0", n) 45 } 46 } 47 }