performance measurements

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

 N  CPU secs Elapsed secs Memory KB Code B ≈ CPU Load
500,0000.420.438,3361274  5% 0% 5% 98%
5,000,0003.563.568,3241274  1% 0% 1% 100%
50,000,00034.9334.9512,9001274  1% 0% 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

Dart VM version: 1.7.2 (Tue Oct 14 06:55:35 2014) on "linux_ia32"

"The Dart team has provided an official benchmark harness that ensures your benchmark follows the benchmarking procedures necessary for the Dart VM’s optimizer."

 n-body Dart #2 program source code

/* The Computer Language Benchmarks Game

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



   contributed by Jos Hirth,

   transliterated from Isaac Gouy and Robert F. Tobler's C# program

*/

import 'dart:math' as Math;

void main(args) {
  int n = args.length > 0 ? int.parse(args[0]) : 0;

  NBodySystem system = new NBodySystem();
  print(system.energy().toStringAsFixed(9));
  for (int i = 0; i < n; i++) {
    system.advance(0.01);
  }
  print(system.energy().toStringAsFixed(9));
}

class Body {
  double x, y, z, vx, vy, vz, mass;
  Body({this.x, this.y, this.z, this.vx, this.vy, this.vz, this.mass});
}

class NBodySystem {
  var bodies;

  static const double solarmass = 4 * Math.PI * Math.PI;
  static const double daysPeryear = 365.24;

  NBodySystem() {
    bodies = new List<Body>();
    bodies.addAll([
      // Sun


      new Body(
        x: 0.0,
        y: 0.0,
        z: 0.0,
        vx: 0.0,
        vy: 0.0,
        vz: 0.0,
        mass: solarmass
      ),
      // Jupiter


      new Body(
        x: 4.84143144246472090e+00,
        y: -1.16032004402742839e+00,
        z: -1.03622044471123109e-01,
        vx: 1.66007664274403694e-03 * daysPeryear,
        vy: 7.69901118419740425e-03 * daysPeryear,
        vz: -6.90460016972063023e-05 * daysPeryear,
        mass: 9.54791938424326609e-04 * solarmass
      ),
      // Saturn


      new Body(
        x: 8.34336671824457987e+00,
        y: 4.12479856412430479e+00,
        z: -4.03523417114321381e-01,
        vx: -2.76742510726862411e-03 * daysPeryear,
        vy: 4.99852801234917238e-03 * daysPeryear,
        vz: 2.30417297573763929e-05 * daysPeryear,
        mass: 2.85885980666130812e-04 * solarmass
      ),
      // Uranus


      new Body(
        x: 1.28943695621391310e+01,
        y: -1.51111514016986312e+01,
        z: -2.23307578892655734e-01,
        vx: 2.96460137564761618e-03 * daysPeryear,
        vy: 2.37847173959480950e-03 * daysPeryear,
        vz: -2.96589568540237556e-05 * daysPeryear,
        mass: 4.36624404335156298e-05 * solarmass
      ),
      // Neptune


      new Body(
        x: 1.53796971148509165e+01,
        y: -2.59193146099879641e+01,
        z: 1.79258772950371181e-01,
        vx: 2.68067772490389322e-03 * daysPeryear,
        vy: 1.62824170038242295e-03 * daysPeryear,
        vz: -9.51592254519715870e-05 * daysPeryear,
        mass: 5.15138902046611451e-05 * solarmass
      )
    ]);

    double px = 0.0, py = 0.0, pz = 0.0;
    for (var b in bodies) {
      px += b.vx * b.mass;
      py += b.vy * b.mass;
      pz += b.vz * b.mass;
    };

    var sol = bodies[0];
    sol.vx = -px / solarmass;
    sol.vy = -py / solarmass;
    sol.vz = -pz / solarmass;
  }

  void advance(double dt) {
    for(int na = 0; na < bodies.length; na++){
      Body a = bodies[na];
      for(int nb = na + 1; nb < bodies.length; nb++){
        Body b = bodies[nb];

        double dx = a.x - b.x,
            dy = a.y - b.y,
            dz = a.z - b.z;
        double d2 = dx * dx + dy * dy + dz * dz;
        double mag = dt / (d2 * Math.sqrt(d2));

        a.vx -= dx * b.mass * mag;
        b.vx += dx * a.mass * mag;

        a.vy -= dy * b.mass * mag;
        b.vy += dy * a.mass * mag;

        a.vz -= dz * b.mass * mag;
        b.vz += dz * a.mass * mag;
      }
    }
    for (var b in bodies) {
      b.x += dt * b.vx;
      b.y += dt * b.vy;
      b.z += dt * b.vz;
    }
  }

  double energy() {
    double e = 0.0;
    for (int i = 0; i < bodies.length; i++) {
      var 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 < bodies.length; j++) {
        var bj = bodies[j];
        double dx = bi.x - bj.x,
            dy = bi.y - bj.y,
            dz = bi.z - bj.z;
        e -= (bi.mass * bj.mass) / Math.sqrt(dx * dx + dy * dy + dz * dz);
      }
    }
    return e;
  }
}

 make, command-line, and program output logs

Sun, 23 Nov 2014 10:32:42 GMT

COMMAND LINE:
/usr/local/src/dart-sdk/bin/dart  nbody.dart-2.dart 50000000

PROGRAM OUTPUT:
-0.169075164
-0.169059907

Revised BSD license

  Home   Conclusions   License   Play