...
Run Format

Source file test/bench/go1/mandel_test.go

     1	// Copyright 2012 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	// This benchmark, taken from the shootuot, tests floating point performance.
     6	
     7	package go1
     8	
     9	import "testing"
    10	
    11	func mandelbrot(n int) int {
    12		const Iter = 50
    13		const Zero float64 = 0
    14		const Limit = 2.0
    15		ok := 0
    16		for y := 0; y < n; y++ {
    17			for x := 0; x < n; x++ {
    18				Zr, Zi, Tr, Ti := Zero, Zero, Zero, Zero
    19				Cr := (2*float64(x)/float64(n) - 1.5)
    20				Ci := (2*float64(y)/float64(n) - 1.0)
    21	
    22				for i := 0; i < Iter && (Tr+Ti <= Limit*Limit); i++ {
    23					Zi = 2*Zr*Zi + Ci
    24					Zr = Tr - Ti + Cr
    25					Tr = Zr * Zr
    26					Ti = Zi * Zi
    27				}
    28	
    29				if Tr+Ti <= Limit*Limit {
    30					ok++
    31				}
    32			}
    33		}
    34		return ok
    35	}
    36	
    37	func BenchmarkMandelbrot200(b *testing.B) {
    38		for i := 0; i < b.N; i++ {
    39			mandelbrot(200)
    40		}
    41	}
    42	

View as plain text