diff options
Diffstat (limited to 'test/bench/mandelbrot.go')
| -rw-r--r-- | test/bench/mandelbrot.go | 62 |
1 files changed, 31 insertions, 31 deletions
diff --git a/test/bench/mandelbrot.go b/test/bench/mandelbrot.go index 6c1b7d4e5..1f9fbfd3d 100644 --- a/test/bench/mandelbrot.go +++ b/test/bench/mandelbrot.go @@ -37,58 +37,58 @@ POSSIBILITY OF SUCH DAMAGE. package main import ( - "bufio"; - "flag"; - "fmt"; - "os"; + "bufio" + "flag" + "fmt" + "os" ) var n = flag.Int("n", 200, "size") func main() { - flag.Parse(); - out := bufio.NewWriter(os.Stdout); - defer out.Flush(); + flag.Parse() + out := bufio.NewWriter(os.Stdout) + defer out.Flush() - w := *n; - h := *n; - bit_num := 0; - byte_acc := byte(0); - const Iter = 50; - const Zero float64 = 0; - const Limit = 2.0; + w := *n + h := *n + bit_num := 0 + byte_acc := byte(0) + const Iter = 50 + const Zero float64 = 0 + const Limit = 2.0 - fmt.Fprintf(out, "P4\n%d %d\n", w, h); + fmt.Fprintf(out, "P4\n%d %d\n", w, h) for y := 0; y < h; y++ { for x := 0; x < w; x++ { - Zr, Zi, Tr, Ti := Zero, Zero, Zero, Zero; - Cr := (2*float64(x)/float64(w) - 1.5); - Ci := (2*float64(y)/float64(h) - 1.0); + Zr, Zi, Tr, Ti := Zero, Zero, Zero, Zero + Cr := (2*float64(x)/float64(w) - 1.5) + Ci := (2*float64(y)/float64(h) - 1.0) for i := 0; i < Iter && (Tr+Ti <= Limit*Limit); i++ { - Zi = 2*Zr*Zi + Ci; - Zr = Tr - Ti + Cr; - Tr = Zr * Zr; - Ti = Zi * Zi; + Zi = 2*Zr*Zi + Ci + Zr = Tr - Ti + Cr + Tr = Zr * Zr + Ti = Zi * Zi } - byte_acc <<= 1; + byte_acc <<= 1 if Tr+Ti <= Limit*Limit { byte_acc |= 0x01 } - bit_num++; + bit_num++ if bit_num == 8 { - out.WriteByte(byte_acc); - byte_acc = 0; - bit_num = 0; + out.WriteByte(byte_acc) + byte_acc = 0 + bit_num = 0 } else if x == w-1 { - byte_acc <<= uint(8 - w%8); - out.WriteByte(byte_acc); - byte_acc = 0; - bit_num = 0; + byte_acc <<= uint(8 - w%8) + out.WriteByte(byte_acc) + byte_acc = 0 + bit_num = 0 } } } |
