1 // Copyright 2023 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.
5 // WARNING: Please avoid updating this file. If this file needs to be updated,
6 // then a new devirt.pprof file should be generated:
8 // $ cd $GOROOT/src/cmd/compile/internal/test/testdata/pgo/devirtualize/
9 // $ go mod init example.com/pgo/devirtualize
10 // $ go test -bench=. -cpuprofile ./devirt.pprof
17 "example.com/pgo/devirtualize/mult.pkg"
20 func BenchmarkDevirtIface(b *testing.B) {
28 ExerciseIface(b.N, a1, a2, m1, m2)
31 // Verify that devirtualization doesn't result in calls or side effects applying more than once.
32 func TestDevirtIface(t *testing.T) {
40 if v := ExerciseIface(10, a1, a2, m1, m2); v != 1176 {
41 t.Errorf("ExerciseIface(10) got %d want 1176", v)
45 func BenchmarkDevirtFuncConcrete(b *testing.B) {
46 ExerciseFuncConcrete(b.N, AddFn, SubFn, mult.MultFn, mult.NegMultFn)
49 func TestDevirtFuncConcrete(t *testing.T) {
50 if v := ExerciseFuncConcrete(10, AddFn, SubFn, mult.MultFn, mult.NegMultFn); v != 1176 {
51 t.Errorf("ExerciseFuncConcrete(10) got %d want 1176", v)
55 func BenchmarkDevirtFuncField(b *testing.B) {
56 ExerciseFuncField(b.N, AddFn, SubFn, mult.MultFn, mult.NegMultFn)
59 func TestDevirtFuncField(t *testing.T) {
60 if v := ExerciseFuncField(10, AddFn, SubFn, mult.MultFn, mult.NegMultFn); v != 1176 {
61 t.Errorf("ExerciseFuncField(10) got %d want 1176", v)
65 func BenchmarkDevirtFuncClosure(b *testing.B) {
66 ExerciseFuncClosure(b.N, AddClosure(), SubClosure(), mult.MultClosure(), mult.NegMultClosure())
69 func TestDevirtFuncClosure(t *testing.T) {
70 if v := ExerciseFuncClosure(10, AddClosure(), SubClosure(), mult.MultClosure(), mult.NegMultClosure()); v != 1176 {
71 t.Errorf("ExerciseFuncClosure(10) got %d want 1176", v)