The Q6600
Benchmarks Game

mandelbrot C++ g++ #3 program

source code

/* The Computer Language Benchmarks Game
   https://salsa.debian.org/benchmarksgame-team/benchmarksgame/
   contributed by Greg Buchholz
   compile:  g++ -O3
*/

#include <stdio.h>
#include <stdlib.h>
#include<iostream>
#include<complex>

int main (int argc, char **argv)
{
  char  bit_num = 0, byte_acc = 0;
  const int iter = 50;
  const double lim = 2.0 * 2.0;
  
  std::ios_base::sync_with_stdio(false);
  int n = atoi(argv[1]);

  std::cout << "P4\n" << n << " " << n << std::endl;

  for(int y=0; y<n; ++y) 
    for(int x=0; x<n; ++x)
    {
       std::complex<double> Z(0,0),C(2*(double)x/n - 1.5, 2*(double)y/n - 1.0);
       
       //manually inlining "norm" results in a 5x-7x speedup on gcc
       for(int i=0; i<iter and Z.real()*Z.real() + Z.imag()*Z.imag() <= lim; ++i)
         Z = Z*Z + C;
        
       byte_acc = (byte_acc << 1) | ((norm(Z) > lim) ? 0x00:0x01);

       if(++bit_num == 8){ std::cout << byte_acc; bit_num = byte_acc = 0; }
       else if(x == n-1) { byte_acc  <<= (8-n%8);
                           std::cout << byte_acc;
                           bit_num = byte_acc = 0; }
    }
}
    

notes, command-line, and program output

NOTES:
64-bit Ubuntu quad core
g++ (Ubuntu 9.3.0-10ubuntu2) 9.3.0


Mon, 04 May 2020 18:36:21 GMT

MAKE:
/usr/bin/g++ -c -pipe -O3 -fomit-frame-pointer -march=core2   mandelbrot.gpp-3.c++ -o mandelbrot.gpp-3.c++.o &&  \
        /usr/bin/g++ mandelbrot.gpp-3.c++.o -o mandelbrot.gpp-3.gpp_run  
rm mandelbrot.gpp-3.c++

5.18s to complete and log all make actions

COMMAND LINE:
./mandelbrot.gpp-3.gpp_run 16000

(BINARY) PROGRAM OUTPUT NOT SHOWN