The Q6600
Benchmarks Game

mandelbrot Swift program

source code

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

   direct transliteration of Greg Buchholz's C program
   contributed by Isaac Gouy, fix by David Turnbull
*/

import Glibc

let w: Int = Int(CommandLine.arguments[1])!
let h = w

var bit_num = 0, i = 0, byte_acc: Int32 = 0
let iter = 50, limit = 2.0
var Zr, Zi, Cr, Ci, Tr, Ti: Double

print("P4\n\(w) \(h)")

for y in 0..<h {
   for x in 0..<w {

      Zr = 0.0; Zi = 0.0; Tr = 0.0; Ti = 0.0
      Cr = 2.0*Double(x)/Double(w) - 1.5; 
      Ci = 2.0*Double(y)/Double(h) - 1.0

      i = 0
      while i < iter && (Tr+Ti <= limit*limit) {
         i += 1
         Zi = 2.0*Zr*Zi + Ci
         Zr = Tr - Ti + Cr
         Tr = Zr * Zr
         Ti = Zi * Zi
      }

      byte_acc <<= 1
      if Tr+Ti <= limit*limit { byte_acc |= 0x01 }

      bit_num += 1

      if bit_num == 8 {
         putc(byte_acc,stdout) // Glibc
         byte_acc = 0
         bit_num = 0
      }
      else if x == w-1 {
         byte_acc <<= (8-w%8)
         putc(byte_acc,stdout) // Glibc
         byte_acc = 0
         bit_num = 0
      }
   }
}
    

notes, command-line, and program output

NOTES:
64-bit Ubuntu quad core
Swift version 5.1.3 (swift-5.1.3-RELEASE)
Target: x86_64-unknown-linux-gnu



Tue, 05 May 2020 19:55:58 GMT

MAKE:
/opt/src/swift-5.1.3-RELEASE-ubuntu18.04/usr/bin/swiftc mandelbrot.swift -Ounchecked -target-cpu core2  -o mandelbrot.swift_run
<unknown>:0: warning: argument unused during compilation: '-mcpu=core2'

13.39s to complete and log all make actions

COMMAND LINE:
./mandelbrot.swift_run 16000

(BINARY) PROGRAM OUTPUT NOT SHOWN