github.com/kintar/etxt@v0.0.9/emask/edge_marker_bench_test.go (about)

     1  //go:build gtxt
     2  
     3  package emask
     4  
     5  import "os"
     6  import "log"
     7  import "math/rand"
     8  import "testing"
     9  
    10  import "golang.org/x/image/math/fixed"
    11  
    12  const rastBenchSeed = int64(0) // use 0 for PID-based seed
    13  func makeRng() *rand.Rand {
    14  	seed := rastBenchSeed
    15  	if seed == 0 {
    16  		seed = int64(os.Getpid())
    17  	}
    18  	return rand.New(rand.NewSource(seed))
    19  }
    20  
    21  func BenchmarkStdRast(b *testing.B) {
    22  	rng := makeRng()
    23  	rast := &DefaultRasterizer{}
    24  	for n := 0; n < b.N; n++ {
    25  		for size := 16; size <= 512; size *= 2 {
    26  			shape := randomShape(rng, 16, size, size)
    27  			segments := shape.Segments()
    28  			_, err := Rasterize(segments, rast, fixed.Point26_6{})
    29  			if err != nil {
    30  				log.Fatalf("rasterization error: %s", err.Error())
    31  			}
    32  		}
    33  	}
    34  }
    35  
    36  func BenchmarkEdgeRast(b *testing.B) {
    37  	rng := makeRng()
    38  	rast := NewStdEdgeMarkerRasterizer()
    39  	for n := 0; n < b.N; n++ {
    40  		for size := 16; size <= 512; size *= 2 {
    41  			shape := randomShape(rng, 16, size, size)
    42  			segments := shape.Segments()
    43  			_, err := Rasterize(segments, rast, fixed.Point26_6{})
    44  			if err != nil {
    45  				log.Fatalf("rasterization error: %s", err.Error())
    46  			}
    47  		}
    48  	}
    49  }