• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
5package ssa
6
7import (
8	"cmd/compile/internal/types"
9	"fmt"
10	"testing"
11)
12
13func BenchmarkCopyElim1(b *testing.B)      { benchmarkCopyElim(b, 1) }
14func BenchmarkCopyElim10(b *testing.B)     { benchmarkCopyElim(b, 10) }
15func BenchmarkCopyElim100(b *testing.B)    { benchmarkCopyElim(b, 100) }
16func BenchmarkCopyElim1000(b *testing.B)   { benchmarkCopyElim(b, 1000) }
17func BenchmarkCopyElim10000(b *testing.B)  { benchmarkCopyElim(b, 10000) }
18func BenchmarkCopyElim100000(b *testing.B) { benchmarkCopyElim(b, 100000) }
19
20func 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