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