The Computer Language
Benchmarks Game

mandelbrot Hack #2 program

source code

<?hh
/* The Computer Language Benchmarks Game
   http://benchmarksgame.alioth.debian.org/
   contributed by Thomas GODART (based on Greg Buchholz's C program)
   modified by anon
   modified by y-uti
*/

function main($argc, $argv) {

    ob_implicit_flush(1);
    ob_start(NULL, 4096);


    $h = ($argc == 2) ? ((int)$argv[1]) : 600;
    $w = $h;

    printf ("P4\n%d %d\n", $w, $h);

    $bit_num = 128;
    $byte_acc = 0;

    $yfac = 2.0 / $h;
    $xfac = 2.0 / $w;

    for ($y = 0 ; $y < $h ; ++$y)
        {
            $result = array('c*');

            $Ci = $y * $yfac - 1.0;

            for ($x = 0 ; $x < $w ; ++$x)
                {
                    $Zr = 0; $Zi = 0; $Tr = 0; $Ti = 0.0;

                    $Cr = $x * $xfac - 1.5;

                    do {
                        for ($i = 0 ; $i < 50 ; ++$i)
                            {
                                $Zi = 2.0 * $Zr * $Zi + $Ci;
                                $Zr = $Tr - $Ti + $Cr;
                                $Tr = $Zr * $Zr;
                                if (($Tr+($Ti = $Zi * $Zi)) > 4.0) break 2;
                            }
                        $byte_acc += $bit_num;
                    } while (FALSE);

                    if ($bit_num === 1) {
                        $result[] = $byte_acc;
                        $bit_num = 128;
                        $byte_acc = 0;
                    } else {
                        $bit_num >>= 1;
                    }
                }
            if ($bit_num !== 128) {
                $result[] = $byte_acc;
                $bit_num = 128;
                $byte_acc = 0;
            }
            echo call_user_func_array('pack', $result);
        }
}

main($argc, $argv);
    

notes, command-line, and program output

NOTES:
64-bit Ubuntu quad core
HipHop VM 3.18.0 (rel)
Compiler: tags/HHVM-3.18.0-0-g9b285191feb2bb1558bb6682da135263bd2a9e60
Repo schema: cc987335f4691fa6ed98336c2378d8e71a751b22


Wed, 15 Feb 2017 02:29:56 GMT

MAKE:
/usr/bin/hh_client
No errors!
0.04s to complete and log all make actions

COMMAND LINE:
/usr/bin/hhvm  mandelbrot.hack-2.hack 16000

(BINARY) PROGRAM OUTPUT NOT SHOWN