Source file src/cmd/compile/internal/ssa/bench_test.go

     1  // Copyright 2020 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  package ssa
     5  
     6  import (
     7  	"math/rand"
     8  	"testing"
     9  )
    10  
    11  var d int
    12  
    13  //go:noinline
    14  func fn(a, b int) bool {
    15  	c := false
    16  	if a > 0 {
    17  		if b < 0 {
    18  			d = d + 1
    19  		}
    20  		c = true
    21  	}
    22  	return c
    23  }
    24  
    25  func BenchmarkPhioptPass(b *testing.B) {
    26  	for i := 0; i < b.N; i++ {
    27  		a := rand.Perm(i/10 + 10)
    28  		for i := 1; i < len(a)/2; i++ {
    29  			fn(a[i]-a[i-1], a[i+len(a)/2-2]-a[i+len(a)/2-1])
    30  		}
    31  	}
    32  }
    33  
    34  type Point struct {
    35  	X, Y int
    36  }
    37  
    38  //go:noinline
    39  func sign(p1, p2, p3 Point) bool {
    40  	return (p1.X-p3.X)*(p2.Y-p3.Y)-(p2.X-p3.X)*(p1.Y-p3.Y) < 0
    41  }
    42  
    43  func BenchmarkInvertLessThanNoov(b *testing.B) {
    44  	p1 := Point{1, 2}
    45  	p2 := Point{2, 3}
    46  	p3 := Point{3, 4}
    47  	for i := 0; i < b.N; i++ {
    48  		sign(p1, p2, p3)
    49  	}
    50  }
    51  

View as plain text