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