performance measurements

Each table row shows performance measurements for this C# Mono program with a particular command-line input value N.

 N  CPU secs Elapsed secs Memory KB Code B ≈ CPU Load
1,0000.340.18?798  44% 89% 37% 28%
4,0003.030.8626,572798  85% 94% 85% 88%
16,00045.8311.6156,416798  98% 99% 99% 99%

Read the ↓ make, command line, and program output logs to see how this program was run.

Read mandelbrot benchmark to see what this program should do.

 notes

Mono JIT compiler version 3.10.1 (master/0083728 Thu Sep 11 09:57:48 PDT 2014)
LLVM: yes(3.4svn-mono-mono/e656cac)
GC: sgen

 mandelbrot C# Mono program source code

/* The Computer Language Benchmarks Game

   http://benchmarksgame.alioth.debian.org/



   Adapted by Antti Lankila from the earlier Isaac Gouy's implementation

   Add multithread & tweaks from C++ by The Anh Tran

*/

using System;
using System.Threading;
using System.IO;

public class MandelBrot
{
    private static int      N = 200;
    private static int      width_bytes;
    
    private static byte[][] data;
   private static int[]    nbyte_each_line;


   public static void Main (String[] args)
   {
      if (args.Length > 0)
         N = Int32.Parse(args[0]);
      Console.Out.WriteLine("P4\n{0} {0}", N);

      width_bytes = N/8;
      if (width_bytes*8 < N)
         width_bytes += 1;

      nbyte_each_line = new int[N];

        data = new byte[N][];
        for (int i = 0; i < N; i++)
            data[i] = new byte[width_bytes];

      Thread[] threads = new Thread[Environment.ProcessorCount];
      for (int i = 0; i < threads.Length; i++)
      {
         threads[i] = new Thread(MandelBrot.Calculate);
            threads[i].Start();
      }

      foreach (Thread t in threads)
         t.Join();

        Stream s = Console.OpenStandardOutput();
      for (int y = 0; y < N; y++)
         s.Write( data[y], 0, nbyte_each_line[y]);
   }


   private static int current_line = -1;

   private static void Calculate()
   {
      double inverse_n = 2.0 / N;

      int y;
      while ((y = Interlocked.Increment(ref current_line)) < N) // fetch a line

      {
            byte[] pdata = data[y];

         int byte_count  = 0;
            int bit_num     = 0;
            int byte_acc    = 0;

            double Civ = y * inverse_n - 1.0;

         for (int x = 0; x < N; x++)
         {
            double Crv = x * inverse_n - 1.5;

            double Zrv   = Crv;
            double Ziv   = Civ;
            double Trv   = Crv * Crv;
            double Tiv   = Civ * Civ;

            int i = 49;
            do
            {
               Ziv = (Zrv*Ziv) + (Zrv*Ziv) + Civ;
               Zrv = Trv - Tiv + Crv;

               Trv = Zrv * Zrv;
               Tiv = Ziv * Ziv;
            }   while ( ((Trv + Tiv) <= 4.0) && (--i > 0) );

            byte_acc <<= 1;
            byte_acc |= (i == 0) ? 1 : 0;

            if (++bit_num == 8)
            {
                    pdata[byte_count] = (byte)byte_acc;
               byte_count++;
               bit_num = byte_acc = 0;
            }
         } // end foreach (column)


         if (bit_num != 0) // write left over bits

         {
            byte_acc <<= (8 - (N & 7));
            pdata[byte_count] = (byte)byte_acc;
            byte_count++;
         }

         nbyte_each_line[y] = byte_count;
      }
   }
};

 make, command-line, and program output logs

Thu, 11 Sep 2014 19:51:22 GMT

MAKE:
mv mandelbrot.csharp mandelbrot.cs
/usr/local/bin/mcs -r:/usr/local/lib/mono/4.5/Mono.Simd.dll -optimize+ -platform:x64 -out:mandelbrot.csharp_run mandelbrot.cs
rm mandelbrot.cs
0.23s to complete and log all make actions

COMMAND LINE:
/usr/local/bin/mono --llvm --gc=sgen mandelbrot.csharp_run 16000

(BINARY) PROGRAM OUTPUT NOT SHOWN

Revised BSD license

  Home   Conclusions   License   Play