File size: 2,330 Bytes
e36aeda | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | // Copyright 2023 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// WARNING: Please avoid updating this file. If this file needs to be updated,
// then a new devirt.pprof file should be generated:
//
// $ cd $GOROOT/src/cmd/compile/internal/test/testdata/pgo/devirtualize/
// $ go mod init example.com/pgo/devirtualize
// $ go test -bench=. -cpuprofile ./devirt.pprof
package devirt
import (
"testing"
"example.com/pgo/devirtualize/mult.pkg"
)
func BenchmarkDevirtIface(b *testing.B) {
var (
a1 Add
a2 Sub
m1 mult.Mult
m2 mult.NegMult
)
ExerciseIface(b.N, a1, a2, m1, m2)
}
// Verify that devirtualization doesn't result in calls or side effects applying more than once.
func TestDevirtIface(t *testing.T) {
var (
a1 Add
a2 Sub
m1 mult.Mult
m2 mult.NegMult
)
if v := ExerciseIface(10, a1, a2, m1, m2); v != 1176 {
t.Errorf("ExerciseIface(10) got %d want 1176", v)
}
}
func BenchmarkDevirtFuncConcrete(b *testing.B) {
ExerciseFuncConcrete(b.N, AddFn, SubFn, mult.MultFn, mult.NegMultFn)
}
func TestDevirtFuncConcrete(t *testing.T) {
if v := ExerciseFuncConcrete(10, AddFn, SubFn, mult.MultFn, mult.NegMultFn); v != 1176 {
t.Errorf("ExerciseFuncConcrete(10) got %d want 1176", v)
}
}
func BenchmarkDevirtFuncField(b *testing.B) {
ExerciseFuncField(b.N, AddFn, SubFn, mult.MultFn, mult.NegMultFn)
}
func TestDevirtFuncField(t *testing.T) {
if v := ExerciseFuncField(10, AddFn, SubFn, mult.MultFn, mult.NegMultFn); v != 1176 {
t.Errorf("ExerciseFuncField(10) got %d want 1176", v)
}
}
func BenchmarkDevirtFuncClosure(b *testing.B) {
ExerciseFuncClosure(b.N, AddClosure(), SubClosure(), mult.MultClosure(), mult.NegMultClosure())
}
func TestDevirtFuncClosure(t *testing.T) {
if v := ExerciseFuncClosure(10, AddClosure(), SubClosure(), mult.MultClosure(), mult.NegMultClosure()); v != 1176 {
t.Errorf("ExerciseFuncClosure(10) got %d want 1176", v)
}
}
func BenchmarkDevirtIfaceZeroWeight(t *testing.B) {
ExerciseIfaceZeroWeight()
}
func TestDevirtIfaceZeroWeight(t *testing.T) {
ExerciseIfaceZeroWeight()
}
func BenchmarkDevirtIndirCallZeroWeight(t *testing.B) {
ExerciseIndirCallZeroWeight()
}
func TestDevirtIndirCallZeroWeight(t *testing.T) {
ExerciseIndirCallZeroWeight()
}
|