Ejemplo n.º 1
0
        static bool Bench(int n, bool verbose)
        {
            NBodySystem bodies        = new NBodySystem();
            double      initialEnergy = bodies.Energy();

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

            if (verbose)
            {
                Console.WriteLine("{0:f9}", finalEnergy);
            }
            double deltaEnergy = Math.Abs(initialEnergy - finalEnergy);
            bool   result      = deltaEnergy < 1e-4;

            if (verbose)
            {
                Console.WriteLine("Energy {0} conserved", result ? "was" : "was not");
            }
            return(result);
        }
Ejemplo n.º 2
0
 public static void Bench()
 {
     int n = 5000000;
     foreach (var iteration in Benchmark.Iterations)
     {
         using (iteration.StartMeasurement())
         {
             NBodySystem bodies = new NBodySystem();
             for (int i = 0; i < n; i++) bodies.Advance(0.01);
         }
     }
 }
Ejemplo n.º 3
0
 public static int Main(String[] args)
 {
     int n = args.Length > 0 ? Int32.Parse(args[0]) : 10000;
     NBodySystem bodies = new NBodySystem();
     double initialEnergy = bodies.Energy();
     Console.WriteLine("{0:f9}", initialEnergy);
     for (int i = 0; i < n; i++) bodies.Advance(0.01);
     double finalEnergy = bodies.Energy();
     Console.WriteLine("{0:f9}", finalEnergy);
     double deltaEnergy = Math.Abs(initialEnergy - finalEnergy);
     bool result = deltaEnergy < 1e-4;
     Console.WriteLine("Energy {0} conserved", result ? "was" : "was not");
     return (result ? 100 : -1);
 }
Ejemplo n.º 4
0
        public static void Bench()
        {
            int n = 5000000;

            foreach (var iteration in Benchmark.Iterations)
            {
                using (iteration.StartMeasurement())
                {
                    NBodySystem bodies = new NBodySystem();
                    for (int i = 0; i < n; i++)
                    {
                        bodies.Advance(0.01);
                    }
                }
            }
        }
Ejemplo n.º 5
0
        public static int Main(String[] args)
        {
            int         n             = args.Length > 0 ? Int32.Parse(args[0]) : 10000;
            NBodySystem bodies        = new NBodySystem();
            double      initialEnergy = bodies.Energy();

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

            Console.WriteLine("{0:f9}", finalEnergy);
            double deltaEnergy = Math.Abs(initialEnergy - finalEnergy);
            bool   result      = deltaEnergy < 1e-4;

            Console.WriteLine("Energy {0} conserved", result ? "was" : "was not");
            return(result ? 100 : -1);
        }