public static void Main (String[] args) { int n = args.Length > 0 ? Int32.Parse(args[0]) : 10000; 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()); }
public void Run(int arg) { NBodySystem bodies = new NBodySystem(); Console.WriteLine("{0:f9}", bodies.Energy()); for (int i = 0; i < arg; i++) { bodies.Advance(0.01); } Console.WriteLine("{0:f9}", bodies.Energy()); }
public static void Main(String[] args) { int n = args.Length > 0 ? Int32.Parse(args[0]) : 10000; 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()); }
public static Tuple <double, double> Main(String[] args) { int n = args.Length > 0 ? Int32.Parse(args[0]) : 10000; NBodySystem bodies = new NBodySystem(); var s = bodies.Energy(); // Console.WriteLine("{0:f9}", bodies.Energy()); for (int i = 0; i < n; i++) { bodies.Advance(0.01); } return(Tuple.Create(s, bodies.Energy())); // Console.WriteLine("{0:f9}", bodies.Energy()); }
public static void Main() { Console.WriteLine("NBody"); int n = 500000; NBodySystem bodies = new NBodySystem(); Console.WriteLine(bodies.Energy()); for (int i = 0; i < n; i++) { bodies.Advance(0.01); } Console.WriteLine(bodies.Energy()); }
public override void RunOnce() { NBodySystem bodies = new NBodySystem(); WriteLine("{0:f9}", bodies.Energy()); for (int i = 0; i < n; i++) { bodies.Advance(0.01); } WriteLine("{0:f9}", bodies.Energy()); }
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); }
public static double[] Main(String[] args) { int n = args.Length > 0 ? Int32.Parse(args[0]) : 10000; NBodySystem bodies = new NBodySystem(); var result = new double[2]; result[0] = bodies.Energy(); for (int i = 0; i < n; i++) { bodies.Advance(0.01); } result[1] = bodies.Energy(); return(result); }
public static void Run(String[] args) { int n = args.Length > 0 ? Int32.Parse(args[0]) : 50_000; //50_000_000; Console.WriteLine("Calculating N-Body for {0} iterations", n); NBodySystem bodies = new NBodySystem(); Console.WriteLine("{0:f9}", bodies.Energy()); var dtStart = DateTime.UtcNow; for (int i = 0; i < n; i++) { bodies.Advance(0.01); } var elapsed = DateTime.UtcNow - dtStart; Console.WriteLine("{0:f9}", bodies.Energy()); Console.WriteLine("Elapsed {0:f3} sec", elapsed.TotalSeconds); }
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); }
public static void Test() { const int n = 10000; NBodySystem.Initialize(); InitialEnergy = (long)Math.Floor(NBodySystem.Energy() * Scale); for (int i = 0; i < n; i++) { NBodySystem.Advance(0.01); } FinalEnergy = (long)Math.Floor(NBodySystem.Energy() * Scale); }
public static void Main(string[] args) { var target = "C#"; if (args.Length > 0) { target = args[0]; } Console.WriteLine($"============ {target} ============"); { Console.WriteLine("##### N-Body #####"); NBodySystem dummy = new NBodySystem(); dummy.Advance(0.01); Func <Int32, TimeSpan> test = (ti) => { NBodySystem bodies = new NBodySystem(); var e = new Elapsed("11"); for (int i = 0; i < 50000000; i++) { bodies.Advance(0.01); } var d = e.Done(); Console.WriteLine($"Try #{ti} : {d}, {bodies.Energy()}"); return(d); }; var times0 = new List <TimeSpan>(10); for (var i = 0; i < 10; i++) { times0.Add(test(i)); } var times = times0.Where(x => x != times0.Min() && x != times0.Max()).ToList(); var average = new TimeSpan((long)times.Select(ts => ts.Ticks).Average()); //Console.WriteLine($"{target} [N-Body] : {average}\n"); using (StreamWriter sw = File.AppendText("averages.txt")) { sw.WriteLine($"{target} [N-Body] : {average}"); } } { Console.WriteLine("##### Spectral-Norm #####"); SpectralNorm.RunGame(0); Func <Int32, TimeSpan> test = (ti) => { var e = new Elapsed("11"); var r = SpectralNorm.RunGame(5500); var d = e.Done(); //Console.WriteLine("{0:f9}", r); Console.WriteLine($"Try #{ti} : {d}, {r}"); return(d); }; var times0 = new List <TimeSpan>(10); for (var i = 0; i < 10; i++) { times0.Add(test(i)); } var times = times0.Where(x => x != times0.Min() && x != times0.Max()).ToList(); var average = new TimeSpan((long)times.Select(ts => ts.Ticks).Average()); //Console.WriteLine($"{target} [Spectral-Norm] : {average}"); using (StreamWriter sw = File.AppendText("averages.txt")) { sw.WriteLine($"{target} [S-Norm] : {average}"); } } { Console.WriteLine("##### Quicksort #####"); Quicksort.DoSort(new Int32[3] { 0, 1, 2 }, 0, 2); Func <Int32, TimeSpan> test = (ti) => { var n = 50000000; var r = new Random(); var array = new Int32[n]; for (var i = 0; i < n; i++) { array[i] = r.Next(0, n); } var e = new Elapsed(""); Quicksort.DoSort(array, 0, n - 1); var d = e.Done(); Console.WriteLine($"Try #{ti} : {d}, {array[1000]}"); return(d); }; var times0 = new List <TimeSpan>(10); for (var i = 0; i < 10; i++) { times0.Add(test(i)); } var times = times0.Where(x => x != times0.Min() && x != times0.Max()).ToList(); var average = new TimeSpan((long)times.Select(ts => ts.Ticks).Average()); //Console.WriteLine($"{target} [Spectral-Norm] : {average}"); using (StreamWriter sw = File.AppendText("averages.txt")) { sw.WriteLine($"{target} [Q-Sort] : {average}"); } } }