The Computer Language
24.04 Benchmarks Game

simple Go program

source code

/* The Computer Language Benchmarks Game
   https://salsa.debian.org/benchmarksgame-team/benchmarksgame/

   line-by-line from Greg Buchholz's C program
*/

package main
import ("bufio"; "fmt"; "os"; "strconv")

func main () {
    bufout := bufio.NewWriter(os.Stdout); defer bufout.Flush()
    var w, h, x, y, i, bit_num int
    var byte_acc byte
    iter := 50
    limit := 2.0
    var Zr, Zi, Cr, Ci, Tr, Ti float64

    w,_ = strconv.Atoi(os.Args[1])
    h = w;

    fmt.Printf("P4\n%d %d\n",w, h)

    for y=0; y<h; y++ {

        for x=0; x<w; x++ {

            Zr = 0.0; Zi = 0.0
            Cr = 2*float64(x)/float64(w) - 1.5; Ci = 2*float64(y)/float64(h) - 1
        
            for i=0; i<iter; i++ {

                Tr = Zr*Zr - Zi*Zi + Cr
                Ti = 2*Zr*Zi + Ci
                Zr = Tr; Zi = Ti
                if Zr*Zr+Zi*Zi > limit*limit {
                    break
                }
            }
            if Zr*Zr+Zi*Zi > limit*limit {
                byte_acc = (byte_acc << 1) | 0x00
            } else {
                byte_acc = (byte_acc << 1) | 0x01
            }    
            bit_num++ 

            if bit_num == 8 {

                bufout.WriteByte(byte_acc)            
                byte_acc = 0
                bit_num = 0

            } else if x == w-1 {

                byte_acc = byte_acc << (8-w%8)
                bufout.WriteByte(byte_acc)
                byte_acc = 0
                bit_num = 0
            }

        }
    }	
}
    

notes, command-line, and program output

NOTES:
64-bit Ubuntu quad core
go version go1.22.0 linux/amd64
GOAMD64=v2


 Fri, 01 Mar 2024 23:54:31 GMT

MAKE:
/opt/src/go1.22.0/go/bin/go build -o simple.go_run simple.go

4.91s to complete and log all make actions

COMMAND LINE:
 ./simple.go_run 16000

(BINARY) PROGRAM OUTPUT NOT SHOWN