The Computer Language
24.11 Benchmarks Game

mandelbrot C# .NET #2 program

source code

/* The Computer Language Benchmarks Game
   https://salsa.debian.org/benchmarksgame-team/benchmarksgame/
 *
 * Adapted by Antti Lankila from the earlier Isaac Gouy's implementation
 */

using System;
using System.IO;

class Mandelbrot {

   public static void Main(String[] args) {

      int width = 100;
      if (args.Length > 0)
	 width = Int32.Parse(args[0]);

      int height = width;
      int maxiter = 50;
      double limit = 4.0;

      Console.WriteLine("P4");
      Console.WriteLine("{0} {1}", width,height);
      Stream s = Console.OpenStandardOutput(1024);

      for (int y = 0; y < height; y++) {
	 int bits = 0;
	 int xcounter = 0;
	 double Ci = 2.0*y/height - 1.0;

         for (int x = 0; x < width; x++){
	    double Zr = 0.0;
	    double Zi = 0.0;
	    double Cr = 2.0*x/width - 1.5;
            int i = maxiter;

            bits = bits << 1;
            do {
               double Tr = Zr*Zr - Zi*Zi + Cr;
               Zi = 2.0*Zr*Zi + Ci;
               Zr = Tr;
               if (Zr*Zr + Zi*Zi > limit) {
		  bits |= 1;
		  break;
	       }
            } while (--i > 0);

            if (++xcounter == 8) {
	       s.WriteByte((byte) (bits ^ 0xff));
	       bits = 0;
	       xcounter = 0;
            }
         }
         if (xcounter != 0)
	    s.WriteByte((byte) ((bits << (8 - xcounter)) ^ 0xff));
      }
   }
}
    

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>false



 Wed, 13 Nov 2024 22:40:45 GMT

MAKE:
cp mandelbrot.csharpcore-2.csharpcore Program.cs
cp Include/csharpcore/program.csproj .
mkdir obj
cp Include/csharpcore/project.assets.json ./obj
/opt/src/dotnet-sdk-9.0.100/dotnet build -c Release --use-current-runtime  	
  Determining projects to restore...
/home/dunham/all-benchmarksgame/benchmarksgame_i53330/mandelbrot/tmp/program.csproj : warning NU1900: Error occurred while getting package vulnerability data: Unable to load the service index for source https://api.nuget.org/v3/index.json.
  Restored /home/dunham/all-benchmarksgame/benchmarksgame_i53330/mandelbrot/tmp/program.csproj (in 6.21 sec).
/home/dunham/all-benchmarksgame/benchmarksgame_i53330/mandelbrot/tmp/program.csproj : warning NU1900: Error occurred while getting package vulnerability data: Unable to load the service index for source https://api.nuget.org/v3/index.json.
  program -> /home/dunham/all-benchmarksgame/benchmarksgame_i53330/mandelbrot/tmp/bin/Release/net9.0/linux-x64/program.dll

Build succeeded.

/home/dunham/all-benchmarksgame/benchmarksgame_i53330/mandelbrot/tmp/program.csproj : warning NU1900: Error occurred while getting package vulnerability data: Unable to load the service index for source https://api.nuget.org/v3/index.json.
/home/dunham/all-benchmarksgame/benchmarksgame_i53330/mandelbrot/tmp/program.csproj : warning NU1900: Error occurred while getting package vulnerability data: Unable to load the service index for source https://api.nuget.org/v3/index.json.
    2 Warning(s)
    0 Error(s)

Time Elapsed 00:00:11.65

13.63s to complete and log all make actions

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

(BINARY) PROGRAM OUTPUT NOT SHOWN