1
2
3
4
5 package ssacompile
6
7 import (
8 "fmt"
9 "testing"
10
11 "cmd/compile/internal/ssa/ssaop"
12 "cmd/compile/internal/types"
13 )
14
15 func BenchmarkCopyElim1(b *testing.B) { benchmarkCopyElim(b, 1) }
16 func BenchmarkCopyElim10(b *testing.B) { benchmarkCopyElim(b, 10) }
17 func BenchmarkCopyElim100(b *testing.B) { benchmarkCopyElim(b, 100) }
18 func BenchmarkCopyElim1000(b *testing.B) { benchmarkCopyElim(b, 1000) }
19 func BenchmarkCopyElim10000(b *testing.B) { benchmarkCopyElim(b, 10000) }
20 func BenchmarkCopyElim100000(b *testing.B) { benchmarkCopyElim(b, 100000) }
21
22 func benchmarkCopyElim(b *testing.B, n int) {
23 c := testConfig(b)
24
25 values := make([]any, 0, n+2)
26 values = append(values, Valu("mem", ssaop.OpInitMem, types.TypeMem, 0, nil))
27 last := "mem"
28 for i := 0; i < n; i++ {
29 name := fmt.Sprintf("copy%d", i)
30 values = append(values, Valu(name, ssaop.OpCopy, types.TypeMem, 0, nil, last))
31 last = name
32 }
33 values = append(values, Exit(last))
34
35 for i := 0; i < len(values)/2; i++ {
36 values[i], values[len(values)-1-i] = values[len(values)-1-i], values[i]
37 }
38
39 for i := 0; i < b.N; i++ {
40 fun := c.Fun("entry", Bloc("entry", values...))
41 Copyelim(fun.f)
42 }
43 }
44
View as plain text