The Computer Language
24.11 Benchmarks Game

mandelbrot C# aot #8 program

source code

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

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


class Mandelbrot {

public static void Main(String[] args) {   
 
    int w, h, bit_num = 0;
    int byte_acc = 0;
    int i, iter = 50;
    double  x, y, limit = 2.0;
    double Zr, Zi, Cr, Ci, Tr, Ti; 
    var stdout = new BufferedStream(Console.OpenStandardOutput());
    h = Int32.Parse(args[0]); w = h;
       
    Console.WriteLine("P4\n{0} {1}", w, h); 
    
    for(y=0;y<h;y++) 
    {
        for(x=0;x<w;x++)
        {
            Zr = 0.0; Zi = 0.0; Tr = 0.0; Ti = 0.0;
            Cr = (2.0*x/w - 1.5); Ci=(2.0*y/h - 1.0);
        
            for (i=0;i<iter && (Tr+Ti <= limit*limit);++i)
            {
                Zi = 2.0*Zr*Zi + Ci;
                Zr = Tr - Ti + Cr;
                Tr = Zr * Zr;
                Ti = Zi * Zi;
            }
        
            byte_acc = byte_acc << 1;
            if(Tr+Ti <= limit*limit) byte_acc |= 0x01;            
            
            ++bit_num;

            if(bit_num == 8)
            {
                stdout.WriteByte((byte)byte_acc);
                byte_acc = 0;
                bit_num = 0;
            }
            else if(x == w-1)
            {
                byte_acc = byte_acc << (8-w%8);
                stdout.WriteByte((byte)byte_acc);
                byte_acc = 0;
                bit_num = 0;
            }
        }
    }	
    stdout.Flush();    
}
}
    

notes, command-line, and program output

NOTES:
64-bit Ubuntu quad core
.NET SDK 9.0.100
Host Version: 9.0.0
Commit: 9d5a6a9aa4

<OutputType>Exe
<TargetFramework>net9.0
<ImplicitUsings>enable
<Nullable>enable
<AllowUnsafeBlocks>true
<ServerGarbageCollection>true
<ConcurrentGarbageCollection>true
<PublishAot>true
<OptimizationPreference>Speed
<IlcInstructionSet>native


 Thu, 14 Nov 2024 00:50:34 GMT

MAKE:
cp mandelbrot.csharpaot-8.csharpaot Program.cs
cp Include/csharpaot/program.csproj .
mkdir obj
cp Include/csharpaot/project.assets.json ./obj
/opt/src/dotnet-sdk-9.0.100/dotnet publish
  Determining projects to restore...
  Restored /home/dunham/all-benchmarksgame/benchmarksgame_i53330/mandelbrot/tmp/program.csproj (in 924 ms).
  program -> /home/dunham/all-benchmarksgame/benchmarksgame_i53330/mandelbrot/tmp/bin/Release/net9.0/linux-x64/program.dll
  Generating native code
  program -> /home/dunham/all-benchmarksgame/benchmarksgame_i53330/mandelbrot/tmp/bin/Release/net9.0/linux-x64/publish/

26.00s to complete and log all make actions

COMMAND LINE:
 ./bin/Release/net9.0/linux-x64/native/program 16000

(BINARY) PROGRAM OUTPUT NOT SHOWN