github.com/go-asm/go@v1.21.1-0.20240213172139-40c5ead50c48/cmd/compile/ssa/copyelim_test.go (about) 1 // Copyright 2016 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 package ssa 6 7 import ( 8 "fmt" 9 "testing" 10 11 "github.com/go-asm/go/cmd/compile/types" 12 ) 13 14 func BenchmarkCopyElim1(b *testing.B) { benchmarkCopyElim(b, 1) } 15 func BenchmarkCopyElim10(b *testing.B) { benchmarkCopyElim(b, 10) } 16 func BenchmarkCopyElim100(b *testing.B) { benchmarkCopyElim(b, 100) } 17 func BenchmarkCopyElim1000(b *testing.B) { benchmarkCopyElim(b, 1000) } 18 func BenchmarkCopyElim10000(b *testing.B) { benchmarkCopyElim(b, 10000) } 19 func BenchmarkCopyElim100000(b *testing.B) { benchmarkCopyElim(b, 100000) } 20 21 func benchmarkCopyElim(b *testing.B, n int) { 22 c := testConfig(b) 23 24 values := make([]interface{}, 0, n+2) 25 values = append(values, Valu("mem", OpInitMem, types.TypeMem, 0, nil)) 26 last := "mem" 27 for i := 0; i < n; i++ { 28 name := fmt.Sprintf("copy%d", i) 29 values = append(values, Valu(name, OpCopy, types.TypeMem, 0, nil, last)) 30 last = name 31 } 32 values = append(values, Exit(last)) 33 // Reverse values array to make it hard 34 for i := 0; i < len(values)/2; i++ { 35 values[i], values[len(values)-1-i] = values[len(values)-1-i], values[i] 36 } 37 38 for i := 0; i < b.N; i++ { 39 fun := c.Fun("entry", Bloc("entry", values...)) 40 Copyelim(fun.f) 41 } 42 }