...

Source file src/cmd/compile/internal/test/testdata/pgo/devirtualize/devirt_test.go

Documentation: cmd/compile/internal/test/testdata/pgo/devirtualize

     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.
     4  
     5  // WARNING: Please avoid updating this file. If this file needs to be updated,
     6  // then a new devirt.pprof file should be generated:
     7  //
     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
    11  
    12  package devirt
    13  
    14  import (
    15  	"testing"
    16  
    17  	"example.com/pgo/devirtualize/mult.pkg"
    18  )
    19  
    20  func BenchmarkDevirtIface(b *testing.B) {
    21  	var (
    22  		a1 Add
    23  		a2 Sub
    24  		m1 mult.Mult
    25  		m2 mult.NegMult
    26  	)
    27  
    28  	ExerciseIface(b.N, a1, a2, m1, m2)
    29  }
    30  
    31  // Verify that devirtualization doesn't result in calls or side effects applying more than once.
    32  func TestDevirtIface(t *testing.T) {
    33  	var (
    34  		a1 Add
    35  		a2 Sub
    36  		m1 mult.Mult
    37  		m2 mult.NegMult
    38  	)
    39  
    40  	if v := ExerciseIface(10, a1, a2, m1, m2); v != 1176 {
    41  		t.Errorf("ExerciseIface(10) got %d want 1176", v)
    42  	}
    43  }
    44  
    45  func BenchmarkDevirtFuncConcrete(b *testing.B) {
    46  	ExerciseFuncConcrete(b.N, AddFn, SubFn, mult.MultFn, mult.NegMultFn)
    47  }
    48  
    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)
    52  	}
    53  }
    54  
    55  func BenchmarkDevirtFuncField(b *testing.B) {
    56  	ExerciseFuncField(b.N, AddFn, SubFn, mult.MultFn, mult.NegMultFn)
    57  }
    58  
    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)
    62  	}
    63  }
    64  
    65  func BenchmarkDevirtFuncClosure(b *testing.B) {
    66  	ExerciseFuncClosure(b.N, AddClosure(), SubClosure(), mult.MultClosure(), mult.NegMultClosure())
    67  }
    68  
    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)
    72  	}
    73  }
    74  

View as plain text