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
500,0000.340.346241289  6% 0% 0% 100%
5,000,0002.542.5421,9321289  0% 0% 1% 100%
50,000,00024.4724.4821,9721289  1% 1% 0% 100%

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

Read n-body benchmark to see what this program should do.

 notes

Mono JIT compiler version 3.8.1 (master/db3eb16 Wed Aug 13 12:36:50 PDT 2014)
LLVM: yes(3.4svn-mono-mono/e656cac)
GC: sgen

 n-body C# Mono #6 program source code

/* The Computer Language Benchmarks Game

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



   contributed by Mark C. Lewis

   modified slightly by Chad Whipkey

   modified by Robert McKee 

*/
using System;
class NBody
{
   public static void Main(String[] args)
   {
      int n = 10000;
      if (args.Length > 0) n = Int32.Parse(args[0]);

      NBodySystem bodies = new NBodySystem();

      Console.WriteLine("{0:f9}", bodies.Energy());
      for (int i = 0; i < n; i++)
         bodies.Advance(0.01);
      Console.WriteLine("{0:f9}", bodies.Energy());
   }
}


class NBodySystem
{
   const double PI = Math.PI;
   const double SOLAR_MASS = 4 * PI * PI;
   const double DAYS_PER_YEAR = 365.24;
   private Body[] bodies;
   const int bl = 5;

   public NBodySystem()
   {
      bodies = new Body[] {
         new Body() { // Sun

            mass = SOLAR_MASS,
         },
         new Body() { // Jupiter

            x = 4.84143144246472090e+00,
            y = -1.16032004402742839e+00,
            z = -1.03622044471123109e-01,
            vx = 1.66007664274403694e-03 * DAYS_PER_YEAR,
            vy = 7.69901118419740425e-03 * DAYS_PER_YEAR,
            vz = -6.90460016972063023e-05 * DAYS_PER_YEAR,
            mass = 9.54791938424326609e-04 * SOLAR_MASS,
         },
         new Body() { // Saturn

            x = 8.34336671824457987e+00,
            y = 4.12479856412430479e+00,
            z = -4.03523417114321381e-01,
            vx = -2.76742510726862411e-03 * DAYS_PER_YEAR,
            vy = 4.99852801234917238e-03 * DAYS_PER_YEAR,
            vz = 2.30417297573763929e-05 * DAYS_PER_YEAR,
            mass = 2.85885980666130812e-04 * SOLAR_MASS,
         },
         new Body() { // Uranus

            x = 1.28943695621391310e+01,
            y = -1.51111514016986312e+01,
            z = -2.23307578892655734e-01,
            vx = 2.96460137564761618e-03 * DAYS_PER_YEAR,
            vy = 2.37847173959480950e-03 * DAYS_PER_YEAR,
            vz = -2.96589568540237556e-05 * DAYS_PER_YEAR,
            mass = 4.36624404335156298e-05 * SOLAR_MASS,
         },
         new Body() { // Neptune

            x = 1.53796971148509165e+01,
            y = -2.59193146099879641e+01,
            z = 1.79258772950371181e-01,
            vx = 2.68067772490389322e-03 * DAYS_PER_YEAR,
            vy = 1.62824170038242295e-03 * DAYS_PER_YEAR,
            vz = -9.51592254519715870e-05 * DAYS_PER_YEAR,
            mass = 5.15138902046611451e-05 * SOLAR_MASS,
         },
      };
      double px = 0;
      double py = 0;
      double pz = 0;
      foreach (Body body in bodies)
      {
         px += body.vx * body.mass;
         py += body.vy * body.mass;
         pz += body.vz * body.mass;
      }
      var sol = bodies[0];
      sol.vx = -px / SOLAR_MASS;
      sol.vy = -py / SOLAR_MASS;
      sol.vz = -pz / SOLAR_MASS;
   }

   public void Advance(double dt)
   {
      double dx, dy, dz, distance, mag, bim, bjm;
      double x, y, z;
      for (int i = 0; i < bl; i++)
      {
         Body bi = bodies[i];
         x = bi.x;
         y = bi.y;
         z = bi.z;

         for (int j = i + 1; j < bl; j++)
         {
            Body bj = bodies[j];
            dx = x - bj.x;
            dy = y - bj.y;
            dz = z - bj.z;

            distance = Math.Sqrt(dx * dx + dy * dy + dz * dz);
            mag = dt / (distance * distance * distance);

            bim = bi.mass * mag;
            bjm = bj.mass * mag;

            bi.vx -= dx * bjm;
            bi.vy -= dy * bjm;
            bi.vz -= dz * bjm;

            bj.vx += dx * bim;
            bj.vy += dy * bim;
            bj.vz += dz * bim;
         }

         bi.x = x + dt * bi.vx;
         bi.y = y + dt * bi.vy;
         bi.z = z + dt * bi.vz;
      }
   }

   public double Energy()
   {
      double dx, dy, dz, distance;
      double e = 0;

      for (int i = 0; i < bl; i++)
      {
         Body bi = bodies[i];
         e += 0.5 * bi.mass * (bi.vx * bi.vx + bi.vy * bi.vy + bi.vz * bi.vz);

         for (int j = i + 1; j < bl; j++)
         {
            Body bj = bodies[j];
            dx = bi.x - bj.x;
            dy = bi.y - bj.y;
            dz = bi.z - bj.z;

            distance = Math.Sqrt(dx * dx + dy * dy + dz * dz);
            e -= (bi.mass * bj.mass) / distance;
         }
      }
      return e;
   }
}


class Body
{
   public double x, y, z, vx, vy, vz, mass;
}

 make, command-line, and program output logs

Thu, 14 Aug 2014 03:47:51 GMT

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

COMMAND LINE:
/usr/local/bin/mono --llvm nbody.csharp-6.csharp_run 50000000

PROGRAM OUTPUT:
-0.169075164
-0.169059907

Revised BSD license

  Home   Conclusions   License   Play