diff options
author | Russ Cox <rsc@golang.org> | 2012-05-30 14:40:59 -0400 |
---|---|---|
committer | Russ Cox <rsc@golang.org> | 2012-05-30 14:40:59 -0400 |
commit | eb056dbea7bf2d18ef582bb637979a7c05b9b6a4 (patch) | |
tree | 34dfa0cced8a6f8323c3bd31dd6e68953ff962c2 /test/bench | |
parent | 3806cc7b05bfa99605d5f8559c4263066a3d8a85 (diff) | |
download | go-eb056dbea7bf2d18ef582bb637979a7c05b9b6a4.tar.gz go-eb056dbea7bf2d18ef582bb637979a7c05b9b6a4.zip |
shootout: make mandelbrot.go more like mandelbrot.c
Surprise! The C code is using floating point values for its counters.
Its off the critical path, but the Go code and C code are supposed to
be as similar as possible to make comparisons meaningful.
It doesn't have a significant effect.
R=golang-dev, r
CC=golang-dev
https://golang.org/cl/6260058
Diffstat (limited to 'test/bench')
-rw-r--r-- | test/bench/shootout/mandelbrot.go | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/test/bench/shootout/mandelbrot.go b/test/bench/shootout/mandelbrot.go index 1f9fbfd3d4..df60343c24 100644 --- a/test/bench/shootout/mandelbrot.go +++ b/test/bench/shootout/mandelbrot.go @@ -50,21 +50,21 @@ func main() { out := bufio.NewWriter(os.Stdout) defer out.Flush() - w := *n - h := *n + w := float64(*n) + h := float64(*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", *n, *n) - for y := 0; y < h; y++ { - for x := 0; x < w; x++ { + for y := 0.0; y < h; y++ { + for x := 0.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) + Cr := (2*x/w - 1.5) + Ci := (2*y/h - 1.0) for i := 0; i < Iter && (Tr+Ti <= Limit*Limit); i++ { Zi = 2*Zr*Zi + Ci @@ -85,7 +85,7 @@ func main() { byte_acc = 0 bit_num = 0 } else if x == w-1 { - byte_acc <<= uint(8 - w%8) + byte_acc <<= uint(8 - uint(*n)%8) out.WriteByte(byte_acc) byte_acc = 0 bit_num = 0 |